Created
October 27, 2016 08:00
-
-
Save fourlastor/4bd415d6db12be8b556376678128606f to your computer and use it in GitHub Desktop.
curry+partial
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
operator fun <P1, P2, R> ((P1, P2) -> R).invoke(): (P1) -> (P2) -> R { | |
return {p1: P1 -> { p2: P2 -> this(p1, p2) } } | |
} | |
operator fun <P1, P2, P3, R> ((P1, P2, P3) -> R).invoke(): (P1) -> (P2) -> (P3) -> R { | |
return {p1: P1 -> { p2: P2 -> { p3: P3 -> this(p1, p2, p3) }}} | |
} | |
fun add(p1: Int, p2: Int): Int = p1 + p2 | |
fun addCurry(): Int { | |
return (::add)()(1)(2) | |
} |
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
operator fun <P1, P2, R> ((P1, P2) -> R).invoke(p1: P1): (P2) -> R { | |
return { p2: P2 -> this(p1, p2) } | |
} | |
operator fun <P1, P2, P3, R> ((P1, P2, P3) -> R).invoke(p1: P1): (P2, P3) -> R { | |
return { p2: P2, p3: P3 -> this(p1, p2, p3) } | |
} | |
fun addThree(p1: Int, p2: Int, p3: Int): Int = p1 + p2 + p3 | |
fun addThreePartial(): Int { | |
return (::addThree)(1)(2)(3) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment