Created
April 15, 2015 23:32
-
-
Save MarioAriasC/77399090e16c85695899 to your computer and use it in GitHub Desktop.
Uncurried functions
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
[Test] fun testUncurrying() { | |
val sum2ints: (Int, Int) -> Int = { x, y -> x + y } | |
val curried: (Int) -> (Int) -> Int = sum2ints.curried() | |
assertEquals(curried(2)(4), 6) | |
//same type as sum2ints, | |
val back: (Int, Int) -> Int = curried.uncurried() | |
assertEquals(back(2, 4), 6) | |
assertEquals(sum2ints(2, 4), 6) | |
val sum3ints: (Int, Int, Int) -> Int = { x, y, z -> x + y } | |
val f: (Int) -> (Int) -> (Int) -> Int =sum3ints.curried() | |
val x: (Int, Int, Int) -> Int =f.uncurried() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment