https://kotlinlang.org logo
#stdlib
Title
# stdlib
r

rrva

07/08/2018, 8:02 AM
If I have a stream of
[a, b, c, d]
what’s a simple and idiomatic way to transform this into a stream of pairs
[[a, b], [c, d]]
r

rrva

07/08/2018, 9:28 AM
does this work on streams as well?
without collecting the stream first
a

Andreas Sinz

07/08/2018, 9:57 AM
are we talking about Java-Streams or Kotlin Sequences?
r

rrva

07/09/2018, 7:41 PM
Java-streams
a

Andreas Sinz

07/09/2018, 8:00 PM
you have three choices: 1. replace
Stream
with
Sequence
and use
chunked
2.
stream.toSequence().chunked(2).toStream()
3. ask on stackoverflow or somewhere else how to do it in pure java
2 Views