Rob Elliot
03/08/2021, 8:41 PMval xs = listOf("a", "e", "c", "b", "d")
xs.takeUntil { it == "c" } == listOf("a", "e", "c")
Shawn
03/08/2021, 8:43 PMtakeWhile {}
not what you’re looking for?Shawn
03/08/2021, 8:44 PMRob Elliot
03/08/2021, 8:44 PMRob Elliot
03/08/2021, 8:46 PMnanodeath
03/08/2021, 9:15 PMval list = listOf("foo")
list.take(list.indexOfFirst { it == "bar" }.takeIf { it >= 0 }?.let { it + 1 } ?: list.size)
ephemient
03/08/2021, 9:34 PMbuildList {
for (elem in list) {
add(elem)
if (predicate(elem)) break
}
}
works with sequence
tooNir
03/08/2021, 10:18 PMephemient
03/08/2021, 10:40 PMemit
instead of add
, but either way you don't need to keep a Boolean var