Sorry for the links, the methods would be:
1) In Collection:
default boolean removeFirstIf(Predicate<? super
E<https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Collection.html>>
filter)
2) In Stream:
Stream<T> skipFirst(Predicate<? super
T<https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/stream/Stream.html>>
predicate)
________________________________
De: Alberto Otero Rodríguez
Enviado: viernes, 2 de julio de 2021 16:22
Para: [email protected] <[email protected]>
Asunto: Methods removeFirstIf in Collection and skipFirst in Stream
Hi,
I think it would be interesting adding the following methods:
1) In Collection:
default boolean
removeFirstIf(Predicate<https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/Predicate.html><?
super
E<https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/Collection.html>>
filter)
2) In Stream:
Stream<https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/stream/Stream.html><T<https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/stream/Stream.html>>
skipFirst(Predicate<https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/function/Predicate.html><?
super
T<https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/stream/Stream.html>>
predicate)
The purpose of both methods would be the same. Deleting the first element in
the collection that fulfills the predicate.
This could be useful in collections/streams with no duplicate elements where
performance would be better than using removeIf from Collection of filter from
Stream.
Regards,
Alberto.