Skip to content

Instantly share code, notes, and snippets.

@kwmt
Created October 15, 2019 05:28
Show Gist options
  • Save kwmt/e17f42c748e7051f88b1c8a0e30c7316 to your computer and use it in GitHub Desktop.
Save kwmt/e17f42c748e7051f88b1c8a0e30c7316 to your computer and use it in GitHub Desktop.
条件にあてはあまるところで止める
var isContinue:Boolean = true
val list = arrayOf("hello", "good", "text", "hello2", "text2")
val result = list.asSequence().takeWhile{isContinue}.reduce {s1, s2->
if(s1.length == 4 && s2.length == 4) {
isContinue = false
return@reduce s1+s2
}
s2
}
if(isContinue) {
println("見つかりませんでした")
} else {
println(result)
}
// Output
// goodtext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment