Created
May 13, 2020 21:42
-
-
Save KisaragiEffective/04dc5e890c19b84165b6059c6de757dc to your computer and use it in GitHub Desktop.
ボイラーコードに、さよなら!w
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
// Currying on Kotlin | |
val s = " " | |
(2..22).forEach { c -> | |
val r = 1..c | |
val indent = s::repeat | |
val generic = r.joinToString(", ") { "E$it" } | |
val retLambda = r.joinToString(" -> ") { "(E$it)" } + " -> R" | |
val argument = r.joinToString(", ") { "e$it" } | |
val head = r.joinToString("\n") { indent(it+1) + indent(1).dropLast(1) + "{ e$it ->" } | |
.drop(s.length * 3 - 1) | |
val body = indent(c+3) + "this@curry($argument)" | |
val tail = (c downTo 1).joinToString("\n") { indent(it + 2) + "}" } | |
println( | |
"""fun <$generic, R> (($generic) -> R).curry(): $retLambda { | |
| return $head | |
|$body | |
|$tail | |
|}""".trimMargin() | |
) | |
println() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment