Last active
August 29, 2015 13:56
-
-
Save f81/9184403 to your computer and use it in GitHub Desktop.
第19章:Scalaでカリー化と部分適用 ref: http://qiita.com/f81@github/items/e8bfab96b4be9e404840
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
scala> val add = {(x:Int, y:Int, z:Int) => x + y + z} | |
add: (Int, Int, Int) => Int = <function3> |
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
[関数名]: (引数) => (戻り値) <functionトレイト> |
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
scala> val addPartialWithX = addPartial(_:Int, _:Int, 5) | |
addPartialWithX: (Int, Int) => Int = <function2> |
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
scala> addPartialWithX(2, 3) | |
res3: Int = 10 |
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
scala> val addPartialNone = addPartial _ | |
addPartialNone: (Int, Int, Int) => Int = <function3> |
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
scala> val addCurried = add.curried | |
addCurried: Int => (Int => (Int => Int)) = <function1> |
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
scala> val addCurriedWithX = addCurried(1) | |
addCurriedWithX: Int => (Int => Int) = <function1> |
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
scala> val addCurriedWithXY = addCurriedWithX(2) | |
addCurriedWithXY: Int => Int = <function1> |
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
scala> addCurriedWithXY(3) | |
res2: Int = 6 |
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
scala> addCurried(1)(2)(3) | |
res1: Int = 6 |
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
scala> def addScalaCurried(x:Int)(y:Int)(z:Int) = x + y + z | |
addScalaCurried: (x: Int)(y: Int)(z: Int)Int |
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
scala> val addScalaCurriedFunc = addScalaCurried _ | |
addScalaCurriedFunc: Int => (Int => (Int => Int)) = <function1> |
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
scala> def addPartial(x:Int, y:Int, z:Int) = x + y + z | |
addPartial: (x: Int, y: Int, z: Int)Int |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment