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 WithIndexrecord along with its zero-based index.

Signature

withIndex()

Examples

Get each element of a stream with its index

Stream .of("A", "B", "C") .gather(Gatherers4j.withIndex()) .toList(); // [ WithIndex(0, "A"), WithIndex(1, "B"), WithIndex(2, "C") ]