Created
September 17, 2012 13:18
-
-
Save stephenLee/3737211 to your computer and use it in GitHub Desktop.
Defining and invoking a curried 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
def curriedSum(x: Int)(y: int) = x + y | |
curriedSum(1)(2) // 3 | |
def first(x: Int) = (y: Int) => x + y | |
val second = first(1) | |
second(2) // 3 | |
// use placeholder notation to use curriedSum in a partially applied function | |
val onePlus = curriedSum(1)_ | |
onePlus(2) // 3 | |
val twoPlus = curriedSum(2)_ | |
onePlus(2) // 4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment