Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yongjhih
Last active May 3, 2023 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yongjhih/fc116ab44364ecb7156169c4ba48e8d9 to your computer and use it in GitHub Desktop.
Save yongjhih/fc116ab44364ecb7156169c4ba48e8d9 to your computer and use it in GitHub Desktop.
fun <T> Sequence<T>.until(predicate: (T) -> Boolean) = sequence {
for (it in this@until) {
if (predicate(it)) break
yield(it)
}
}
fun <T> Sequence<T>.untilInclusive(predicate: (T) -> Boolean) = sequence {
for (it in this@untilInclusive) {
yield(it)
if (predicate(it)) break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment