Created
September 4, 2018 23:16
-
-
Save bitops/3b614629fa1c4c5894bbe83cdad0e7a8 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
// pipe-forward operator | |
precedencegroup ForwardApplication { | |
associativity: left | |
} | |
infix operator |>: ForwardApplication | |
func |> <A, B>(a: A, f: (A) -> B) -> B { | |
return f(a) | |
} | |
// non-curried add | |
func add(a: Int, b: Int) -> Int { | |
return a + b | |
} | |
// curried version of add | |
func addCurry(a: Int) -> (Int) -> Int { | |
return { b in | |
return a + b | |
} | |
} | |
// partial application | |
let addOne = addCurry(a: 1) | |
// both of these return 2 | |
1 |> addOne | |
1 |> addCurry(a: 1) | |
// returns 3 | |
1 |> addCurry(a: 1) |> addOne | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment