Created
October 31, 2016 04:17
-
-
Save Qata/21cd92d0b90410efe055d57152ebd9c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
precedencegroup ForwardApplicationPrecedence { | |
associativity: left | |
} | |
/// Applies `f` to `arg`. | |
infix operator |> : ForwardApplicationPrecedence | |
func |> <T, U>(arg: T, f: (T) -> U) -> U { | |
return f(arg) | |
} | |
//Compiles immediately | |
let value = 25.0 | |
|> {(value: Double) in value + 1 } | |
|> {(value: Double) in value * 20 } | |
|> {(value: Double) in value / 10 } | |
|> {(value: Double) in value == 52.0 } | |
|> (!) | |
//Takes a billion years to give up | |
let value = 25.0 | |
|> { $0 + 1 } | |
|> { $0 * 20 } | |
|> { $0 / 10 } | |
|> { $0 == 52.0 } | |
|> (!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment