Created
June 5, 2014 19:29
-
-
Save plumhead/774fb1cb62137679890c to your computer and use it in GitHub Desktop.
Swift Pipe Example
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
operator infix |> {associativity left precedence 140} | |
func |> <T,U> (left: @auto_closure () -> T,right: T -> U) -> U { | |
return right(left()) | |
} | |
func add(n1 : Int)(n2: Int) -> Int {return n1 + n2} | |
let addone = add(1) | |
let addtwo = add(2) | |
let a1 = addone(n2:10) |> addone |> addtwo | |
let a2 = 1 | |
|> addone | |
|> {$0 + 3} | |
|> {(n : Int) -> Int in return n * 2} | |
|> addtwo | |
"andy" |> {"hello \($0)"} |> println | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment