Skip to content

Instantly share code, notes, and snippets.

@d-date
Created September 3, 2018 19:48
Show Gist options
  • Save d-date/3b754ad209620c4cc3d4aa4baf15a58b to your computer and use it in GitHub Desktop.
Save d-date/3b754ad209620c4cc3d4aa4baf15a58b to your computer and use it in GitHub Desktop.
talking about currying #CodePiece #tryswiftnyc
// Currying:
// curry((A, B) _> C) -> ((A) -> ((B) -> C)
func map<A, B>(
_ f: @escaping (A) -> B)
-> ([A]) -> [B] {
return { xs in xs.map(f) }
}
map(incr) // (Array<Int>) -> Array<Int>
map(square) // (Array<Int>) -> Array<Int>
Array(1...10) |> map(incr) >>> map(square)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment