Skip to content

Instantly share code, notes, and snippets.

@gaplo917
Last active January 15, 2017 17:52
Show Gist options
  • Save gaplo917/eecb53373c4737cfedce073e4d8232b6 to your computer and use it in GitHub Desktop.
Save gaplo917/eecb53373c4737cfedce073e4d8232b6 to your computer and use it in GitHub Desktop.
Kotlin Function Support 4
// 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