Created
June 4, 2014 19:41
-
-
Save jmont/65d5bd875ea2c7fbc938 to your computer and use it in GitHub Desktop.
[WIP] Function Composition in Swift
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 } | |
func -%-<TypeA, TypeB, TypeC> (f: TypeB -> TypeC, g: TypeA -> TypeB) -> (TypeA -> TypeC) { | |
return ({ x in f(g(x)) }) | |
} | |
func add3(x:Int) -> Int { | |
return x + 3; | |
} | |
func add7(x: Int) -> Int { | |
return x + 7; | |
} | |
var add10 = add3 -%- add7 | |
add10(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment