-
-
Save codeforfun-jp/179b951014a2e77d305d113d53c177f8 to your computer and use it in GitHub Desktop.
[Kotlin Intro] Function Types & Lambda 2-4
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
fun main() { | |
val game1 = playGame(true) | |
game1() | |
val game2 = playGame(false) | |
game2() | |
} | |
fun playGame(isWin: Boolean): () -> Unit { | |
return if (isWin) win else lose | |
} | |
val win = { println("勝ち") } | |
val lose = { println("負け") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment