aaverin
11/28/2018, 9:05 AMlistOf(1,2,3,4,5).forEach {
if (it > 3) //actually evaluates 5 times
return@forEach
}
Any way to stop forEach without using the label?spand
11/28/2018, 9:08 AMbreakdiego-gomez-olvera
11/28/2018, 9:08 AMfirstOrNull?diego-gomez-olvera
11/28/2018, 9:09 AMfilter if you need all of themaaverin
11/28/2018, 9:09 AMaaverin
11/28/2018, 9:10 AMlistOf(errorResolutions).forEach{
if (it.resolvesError()) {
return@foreEach
}
}aaverin
11/28/2018, 9:11 AMgsala
11/28/2018, 9:14 AM.takeWhile {} or I'm pretty sure .any{} will stop as soon as one is foundspand
11/28/2018, 9:19 AMspand
11/28/2018, 9:21 AMaaverin
11/28/2018, 9:23 AMtakeWhile {} suggestion
I think it will work perfectly in this caseaaverin
11/28/2018, 9:23 AMigor.wojda
11/28/2018, 9:59 AMgildor
11/28/2018, 10:07 AMreturn to check itigor.wojda
11/28/2018, 11:00 AMradityagumay
11/29/2018, 4:20 PMtakeWhile is best choice