filterIndexed()
Filter a stream according to a given
predicate
, which takes both the item being examined and its index.Implementation Notes
Signature
filterIndexed(BiPredicate<Long, INPUT> predicate)
predicate
- A non-nullBiPredicate<Long,INPUT>
where theLong
is the zero-based index of the element being filtered, and theINPUT
is the element itself.
Examples
Keep the even-numbered elements, and anything that equals “T”
Stream
.of("A", "B", "C", "T")
.gather(Gatherers4j.filterWithIndex((index, element) -> index % 2 == 0 || element.equals("T")))
.toList();
// ["A", "C", "T"]