Discussion: Introduce a `Stream.reject` method, the opposite of `Stream.filter`

Jacob Glickman jhg023 at bucknell.edu
Fri May 18 18:22:18 UTC 2018


Seeing as `Predicate.not` was just proposed, I think it would be a good
idea to also introduce `Stream.reject`, which would be logically equivalent
to calling `Stream.filter` with a negated `Predicate`, but with fewer
method calls.

Instead of:

    Stream.of("", "A", "B", "C")
         .filter(s -> !s.isEmpty())
         .count();

You could call:

    Stream.of("", "A", "B", "C")
         .reject(String::isEmpty)
         .count();

I welcome any suggestions for better names other than `reject`.  If this
suggestion is supported, then I'll happily submit an RFE and the code,
tests, etc.

- Jacob


More information about the core-libs-dev mailing list