Skip to content

Instantly share code, notes, and snippets.

@yongjhih
Last active May 3, 2023 14:58
Show Gist options
  • Select an option

  • Save yongjhih/fc116ab44364ecb7156169c4ba48e8d9 to your computer and use it in GitHub Desktop.

Select an option

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