Last active
January 15, 2017 17:52
-
-
Save gaplo917/eecb53373c4737cfedce073e4d8232b6 to your computer and use it in GitHub Desktop.
Kotlin Function Support 4
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
// Kotlin - currying function example | |
fun doCurrying(first: Int): (Int) -> ((Int, Int) -> Int) -> Int { | |
return { second -> { f -> f(first,second) } } | |
} | |
val add = { a: Int, b: Int -> a + b } | |
val multiply = { a: Int, b: Int -> a * b } | |
val minus = { a: Int, b: Int -> a - b } | |
val curriedFour = doCurrying(4) | |
val curriedFourFive = curriedFour(5) | |
curriedFourFive(add) // 9 | |
curriedFourFive(multiply) // 20 | |
curriedFourFive(minus) // -1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment