Skip to content

Instantly share code, notes, and snippets.

@priort
Last active July 12, 2019 20:37
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 priort/bfecde8b6f0f2f532c1bf22c88557fef to your computer and use it in GitHub Desktop.
Save priort/bfecde8b6f0f2f532c1bf22c88557fef to your computer and use it in GitHub Desktop.
fun <E> dropWhile(list: List<E>, f: (E) -> Boolean): List<E> {
tailrec fun loop(remaining: List<E>): List<E> =
when(remaining) {
is Empty -> remaining
is Cons -> if (f(remaining.head)) loop(remaining.tail) else remaining
}
return loop(list)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment