Skip to content

Instantly share code, notes, and snippets.

@FWeinb
Created June 13, 2014 18:44
Show Gist options
  • Save FWeinb/b911452474bdc131facf to your computer and use it in GitHub Desktop.
Save FWeinb/b911452474bdc131facf to your computer and use it in GitHub Desktop.
Some fun with swift
// Pipe operator
operator infix | {
associativity left
}
// Use the left side as a parameter for the function on the right.
func |<T, R>(left:T, right:(T) -> (R) ) -> R { return right(left) }
var upperCase:(String) -> (String) = { $0.uppercaseString }
// Pipe "test" through upperCase
"test" | upperCase
// Use a curried Function
func incrementGenerator(by:Int)(inc:Int) -> (Int){
return inc + by;
}
var incBy5 = incrementGenerator(5);
5 | incBy5 | incBy5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment