Created
July 8, 2018 15:52
-
-
Save Takhion/669d7873a0425161304cee729ad08401 to your computer and use it in GitHub Desktop.
Multiple receivers in Kotlin
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
val sample: (X, Y, Z) -> Int = multiReceiver { { { x + y + z } } } | |
fun <A, B, C, R> multiReceiver(f: A.() -> B.() -> C.() -> R) = { a: A, b: B, c: C -> f(a)(b)(c) } | |
class X(val x: Int) | |
class Y(val y: Int) | |
class Z(val z: Int) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would have saved me hours if someone told me, how to actually call sample now.
Answer is:
sample(X(1), Y(2), Z(3))
I hope that helps future desperate souls looking for ways to accept multiple receivers.
Everyone trying to find out what sample would look like without the multiReceiver helper: