Skip to content

Instantly share code, notes, and snippets.

@hamsternik
Created January 30, 2019 01:50
Show Gist options
  • Save hamsternik/12541adc9305b850cc88975a03de798d to your computer and use it in GitHub Desktop.
Save hamsternik/12541adc9305b850cc88975a03de798d to your computer and use it in GitHub Desktop.
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