Skip to content

Instantly share code, notes, and snippets.

@jmont
Created June 4, 2014 19:41
Show Gist options
  • Save jmont/65d5bd875ea2c7fbc938 to your computer and use it in GitHub Desktop.
Save jmont/65d5bd875ea2c7fbc938 to your computer and use it in GitHub Desktop.
[WIP] Function Composition in Swift
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