Skip to content

Instantly share code, notes, and snippets.

@Pooh3Mobi
Created January 13, 2019 02:31
Show Gist options
  • Save Pooh3Mobi/1c8cad335ac8c280a79f82e912ad7b5d to your computer and use it in GitHub Desktop.
Save Pooh3Mobi/1c8cad335ac8c280a79f82e912ad7b5d to your computer and use it in GitHub Desktop.
Kotlin 無理やり束縛例
// 計算結果を束縛
fun judgeBMI(weight: Double, height: Double): String {
return when (
val bmi = (height / 100)
.let { weight / (it * it) }
) {
in 0.0..18.5 -> "Low weight $bmi"
in 18.5..25.0 -> "Normal (healthy weight)"
in 25.0..30.0 -> "Obese Class I"
in 30.0..35.0 -> "Obese Class II"
in 35.0..40.0 -> "Obese Class III"
else -> "Too match fat"
}
}
// 関数を束縛
fun hello(name: String): String {
return { "Mr.$name" }.let {
"Hello, ${it()}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment