Is there a simpler version of zip, that doesn’t bu...
# getting-started
m
Is there a simpler version of zip, that doesn’t build a sequence? Rather, we just do the work in the transform block?
m
What do you mean? Can you make an example?
m
seq1.zip(seq2) { (s1, s2) -> doWork(s1, s2) }
So I don’t need the returned sequence
Oh, I still need to iterate over it, of course
k
I think there is a
zipWith
m
You could do this:
Copy code
seq1.zip(seq2).forEach { (s1, s2) ->
  doWork(s1, s2)
}
k
Oh, I misread the question
m
@marstran yep, though it’s still creating a new sequence. No big deal though.
m
Yes, but it's only 1 object creation. It doesn't process anything until
forEach
, like it would if it was a list.
k
It allocates a bunch of pairs though
m
@Kroppeb Yeah, true, it does it when consumed. I guess
seq1.zip(seq2) { a, b -> doWork(s1, s2) }.forEach {}
avoids it, but it looks weird 😛