Created
December 24, 2016 21:03
-
-
Save matklad/54776705250e3b375618f59a8247a237 to your computer and use it in GitHub Desktop.
An "inclusive" version of Kotlin's takeWhile
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
fun <T> Sequence<T>.takeWhileInclusive(pred: (T) -> Boolean): Sequence<T> { | |
var shouldContinue = true | |
return takeWhile { | |
val result = shouldContinue | |
shouldContinue = pred(it) | |
result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I love this. If Sequence were parallel, though, wouldn't there be worries about using out-of-closure state?