Created
October 18, 2015 06:46
-
-
Save antsmartian/9d074ed34f76ee83c5ab to your computer and use it in GitHub Desktop.
curryingLeadsToComposition
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
//: 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