Last active
August 29, 2015 14:12
-
-
Save gilesvangruisen/d01d901f128be39a5e8b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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