Skip to content

Instantly share code, notes, and snippets.

@plumhead
Created June 5, 2014 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plumhead/774fb1cb62137679890c to your computer and use it in GitHub Desktop.
Save plumhead/774fb1cb62137679890c to your computer and use it in GitHub Desktop.
Swift Pipe Example
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