Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created November 18, 2024 06:13
Show Gist options
  • Save codeforfun-jp/179b951014a2e77d305d113d53c177f8 to your computer and use it in GitHub Desktop.
Save codeforfun-jp/179b951014a2e77d305d113d53c177f8 to your computer and use it in GitHub Desktop.
[Kotlin Intro] Function Types & Lambda 2-4
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