Created
January 8, 2015 04:23
-
-
Save Nkzn/4c88a2d1a510d994276b to your computer and use it in GitHub Desktop.
カリー化の練習
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
| // カリー化されていない関数 | |
| func uncurriedAdd(let a:Int, let b:Int) -> Int { | |
| return a + b | |
| } | |
| uncurriedAdd(1, 2) // 3 | |
| uncurriedAdd(2, 23) // 25 | |
| uncurriedAdd(4, 2) // 6 | |
| // カリー化された関数 | |
| func curryedAdd(let a: Int) -> (Int) -> Int { | |
| return { (let b: Int) -> Int in | |
| return a + b | |
| } | |
| } | |
| let add1 = curryedAdd(1) // 部分適用 | |
| add1(2) // 3 | |
| add1(3) // 4 | |
| curryedAdd(1)(2) // 3 | |
| curryedAdd(2)(23) // 25 | |
| curryedAdd(4)(2) // 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
s/curryed/curried/g