Currying:
http://www.objc.io/blog/2014/11/10/functional-snippet-6-currying/
https://robots.thoughtbot.com/introduction-to-function-currying-in-swift
func add(a: Int)( b: Int) -> Int {
return a + b
}
let b = add(5)
b(b: 3) // 8
b(b: 4) // 9
func subtract(a: Int, b: Int) -> Int {
return a - b
}
func curry<A, B, C>(f: (A, B) -> C) -> A -> B -> C {
return { a in { b in f(a, b) } }
}
let sub = curry(subtract)
let ten = sub(10)
ten(9) // 1
ten(8) // 2
ten(7) // 3
func curry<A, B, C, R>(f: (A, B, C) -> R) -> A -> B -> C -> R {
return { a in { b in { c in f(a, b, c) } } }
}
let curriedLogin2 = curry(login)