Skip to content

Instantly share code, notes, and snippets.

@bartcone
Created July 13, 2015 01:42
Show Gist options
  • Save bartcone/ce9e729d1b89bb928175 to your computer and use it in GitHub Desktop.
Save bartcone/ce9e729d1b89bb928175 to your computer and use it in GitHub Desktop.
Swift: Curry && Uncurry
func curry <A, B, C> (f: (A, B) -> C) -> A -> (B -> C) {
return { (a: A) -> (B -> C) in
return { (b: B) -> C in
return f(a,b)
}
}
}
func uncurry <A, B, C> (f: 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