Created
October 15, 2019 05:28
-
-
Save kwmt/e17f42c748e7051f88b1c8a0e30c7316 to your computer and use it in GitHub Desktop.
条件にあてはあまるところで止める
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
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