Skip to content

Instantly share code, notes, and snippets.

@jarsen
Last active August 29, 2015 14:12
Show Gist options
  • Save jarsen/8b23afc1ca6f8f636f72 to your computer and use it in GitHub Desktop.
Save jarsen/8b23afc1ca6f8f636f72 to your computer and use it in GitHub Desktop.
swift function composition using UTF-8 ring operator
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