Created
June 9, 2016 02:09
-
-
Save hisui/7d429f9787716d303ae5acb3c97dd288 to your computer and use it in GitHub Desktop.
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
class Human(val name: String, val age: Int, val children: List<Human>) | |
val age: Int? = null | |
print(::Human.curry() `$` "John" `*` age `*` listOf<Human>()) // == null | |
print(::Human.curry() `$` "Mary" `*` 999 `*` listOf<Human>()) // != null |
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
fun<A, B, Z> Function2<A, B, Z>.curry(): (A) -> (B) -> Z { | |
return { a: A -> { b: B -> this(a, b) } } | |
} | |
fun<A, B, C, Z> Function3<A, B, C, Z>.curry(): (A) -> (B) -> (C) -> Z { | |
return { a: A -> { b: B -> { c: C -> this(a, b, c) } } } | |
} | |
infix fun<A, B> Function1<A, B>?.`*`(a: A?): B? = this?.let { f -> a?.let(f) } | |
infix fun<A, B> Function1<A, B> .`$`(a: A?): B? = this `*` a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment