withIndex()
Maps all elements of the stream as-is along with their 0-based index.
Implementation Notes
Each element of the input stream is mapped to a IndexedValue
record along with its zero-based index. As of now
does not provide a mapWithIndex()
functionality but that is on the roadmap.
Signature
withIndex()
Examples
Get each element of a stream with its index
Stream
.of("A", "B", "C");
.gather(Gatherers4j.withIndex())
.toList();
// [ IndexedValue(0, "A"), IndexedValue(1, "B"), IndexedValue(2, "C") ]