Skip to content

Instantly share code, notes, and snippets.

@gilesvangruisen
Last active August 29, 2015 14:12
Show Gist options
  • Save gilesvangruisen/d01d901f128be39a5e8b to your computer and use it in GitHub Desktop.
Save gilesvangruisen/d01d901f128be39a5e8b to your computer and use it in GitHub Desktop.
infix operator --> { associativity left precedence 160 }
func --><T, S>(argument: T?, body: (T) -> (S)) -> S? {
if let value = argument {
return body(value) as S
} else {
return nil
}
}
// Example:
func addTen(num: Int) -> Int {
return num + 10
}
func double(num: Int) -> Int {
return num * 2
}
2 --> addTen --> double --> println // prints 24
// or
2
--> addTen
--> double
--> println // prints 24
// equivelant to:
println(double(addTen(2))) // prints 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment