Created
January 30, 2019 01:50
-
-
Save hamsternik/12541adc9305b850cc88975a03de798d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/// One-parameter currying from two arguments function | |
typealias EscapingClosure<A, B> = (A) -> B | |
func curry<A, B, C>(_ f: @escaping (A, B) -> C) -> EscapingClosure<A, (B) -> C> { | |
return { (a: A) -> ((_ b: B) -> C) in | |
return { (b: B) -> C in f(a, b) } | |
} | |
} | |
func uncurry<A, B, C>(_ f: @escaping EscapingClosure<A, (B) -> C>) -> (A, B) -> C { | |
return { (a: A, b: B) -> C in | |
return f(a)(b) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment