Skip to content

Instantly share code, notes, and snippets.

@kmdsbng
Created April 13, 2018 10:20
Show Gist options
  • Save kmdsbng/b621a1898f75fef1b0cc542f6cfb8000 to your computer and use it in GitHub Desktop.
Save kmdsbng/b621a1898f75fef1b0cc542f6cfb8000 to your computer and use it in GitHub Desktop.
tailrec fun <T, R> Iterable<T>.mapWithConsIter(result: Cons<R>, src: Iterator<T>, cb: (T) -> R): List<R> {
if (!src.hasNext()) {
return result
}
val e = src.next()
return mapWithConsIter(Cons<R>(cb(e), result), src, cb)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment