Last active
August 29, 2015 14:12
-
-
Save jarsen/8b23afc1ca6f8f636f72 to your computer and use it in GitHub Desktop.
swift function composition using UTF-8 ring operator
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 ∘ {} | |
func ∘<A,B,C>(f:B->C, g:A->B) -> (A->C) { | |
return compose(f, g) | |
} | |
func compose<A,B,C>(f:B->C, g:A->B) -> (A->C) { | |
return { x in f(g(x)) } | |
} | |
func add1(x: Int) -> Int { | |
return x + 1 | |
} | |
func description<P: Printable>(p: P) -> String { | |
return p.description | |
} | |
(description ∘ add1)(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment