Skip to content

Instantly share code, notes, and snippets.

@Qata
Created October 31, 2016 04:17
Show Gist options
  • Save Qata/21cd92d0b90410efe055d57152ebd9c0 to your computer and use it in GitHub Desktop.
Save Qata/21cd92d0b90410efe055d57152ebd9c0 to your computer and use it in GitHub Desktop.
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