Stream Method Proposal: long count(Predicate<? super T> predicate)
jhg023 at bucknell.edu
Thu Nov 8 14:07:28 UTC 2018
There was a typo in my last e-mail:
`.count("Java::equals")` should be `.count("Java"::equals)`
On Thu, Nov 8, 2018 at 9:02 AM Jacob Glickman <jhg023 at bucknell.edu> wrote:
> Nothing is wrong with it, but I think the addition of the convenience
> method(s) would help to improve readability in some cases. Personally, I'd
> much rather have the option of writing `.count("Java::equals")` than
> `.filter("Java"::equals).count()`. As Zheka stated, this type of
> convenience method could also be useful for findFirst, in addition to
> findAny, distinct, etc.
> Jacob Glickman
> On Thu, Nov 8, 2018 at 4:46 AM Tagir Valeev <amaembo at gmail.com> wrote:
>> What's wrong with `filter(predicate).count()`? Saving nine characters?
>> With best regards,
>> Tagir Valeev.
>> On Thu, Nov 8, 2018 at 8:02 AM 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
>> > it be to add an overloaded count() method that accepts a Predicate,
>> > it uses as a filter before returning the count of elements in the
>> > 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