Created
May 25, 2019 17:09
-
-
Save pksokolowski/b3e725bc1331a54a77cc13f604b8914a to your computer and use it in GitHub Desktop.
Kotlin events, with one and many listeners.
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
private fun raiseMoveMade() = moveMade.forEach { it.invoke() } | |
val moveMade = mutableListOf<() -> Unit>() | |
// invoking | |
raiseMoveMade() | |
// assigning a listener (in the outside world) | |
moveMade += { uiSounds.playMove() } |
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
var moveMade: (() -> Unit)? = null | |
// invoking | |
moveMade?.invoke() | |
// assignment | |
moveMade = { uiSounds.playMove() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment