Skip to content

Instantly share code, notes, and snippets.

@antsmartian
Created October 18, 2015 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antsmartian/9d074ed34f76ee83c5ab to your computer and use it in GitHub Desktop.
Save antsmartian/9d074ed34f76ee83c5ab to your computer and use it in GitHub Desktop.
curryingLeadsToComposition
//: Playground - noun: a place where people can play
import UIKit
func add(a: Int)(b: Int) -> Int {
return a + b
}
func div(a: Int)(b: Int) -> Int {
return a % b
}
let addTwo = add(2)
let divTwo = div(2)
infix operator <<< { associativity left }
func <<< <A, B, C>(f: B -> C, g: A -> B) -> A -> C {
return { x in f(g(x)) }
}
let newFn = divTwo <<< addTwo
newFn(6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment