Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An "inclusive" version of Kotlin's takeWhile
fun <T> Sequence<T>.takeWhileInclusive(pred: (T) -> Boolean): Sequence<T> {
var shouldContinue = true
return takeWhile {
val result = shouldContinue
shouldContinue = pred(it)
result
}
}
@wafisher

This comment has been minimized.

Copy link

commented May 13, 2017

I love this. If Sequence were parallel, though, wouldn't there be worries about using out-of-closure state?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.