Made a lazy `Iterable<A>.zip(Iterable<B&g...
# language-proposals
s
Made a lazy
Iterable<A>.zip(Iterable<B>)
version similar to
Iterable.withIndex()
that returns an
Iterable<Pair<A, B>>
instead of what
withIndex()
returns (viz.
Iterable<Pair<T, Int>
). I called it
Iterable.with(Iterable): ZippingIterable
(instead of
IndexingIterable
for
withIndex()
). It seems like a natural corollary to
withIndex()
and a common enough use case (viz. two Iterables, want to zip like
zip
but want it lazy like
withIndex
). Thoughts?
e
isn't that just
Sequence
?
☝️ 2
☝🏼 1
s
How would you use sequence to accomplish this?
e
Copy code
fun <T, U> Iterable<T>.with(other: Iterable<U>): Iterable<Pair<T, U
> =
    this.asSequence()
        .zip(other.asSequence())
        .asIterable()
but there should be no need for this function and in most uses you won't need
.asIterable()
in the end either
🤯 1
s
Why should there be no need for this function? And why no need for
asIterable()
?
e
if you care about lazy processing, you're likely to be working with sequences to begin with; just add
.asSequence()
in the caller to adapt the things that aren't. and almost all of the iterable operations you would want to follow it up with, also exist on sequence, so there's rarely a need to use
.asIterable()
to create a wrapper