Stream Method Proposal: long count(Predicate<? super T> predicate)

Zheka Kozlov orionllmain at gmail.com
Thu Nov 8 01:32:03 UTC 2018


findFirst(Predicate<? super T> predicate) would be nice too

чт, 8 нояб. 2018 г. в 8:01, Jacob Glickman <jhg023 at bucknell.edu>:

>  Hello!
>
> I see myself having to often call count() as a terminal operation on a
> Stream immediately after performing a filter operation. How feasible would
> it be to add an overloaded count() method that accepts a Predicate, which
> it uses as a filter before returning the count of elements in the Stream?
> If this is supported, I'd gladly create the webrev & tests for it!
>
> I suppose the method signature can be something along the lines of:
>
>     long count(Predicate<? super T> predicate)
>
> It would also seem reasonable to give this method to IntStream,
> DoubleStream, and LongStream, but allowing them to use IntPredicate,
> DoublePredicate, and LongPredicate respectively.
>
> Thanks,
>
> Jacob Glickman
>


More information about the core-libs-dev mailing list