Discussion: Introduce a Stream.reject method, the opposite of Stream.filter (original) (raw)

Paul Sandoz paul.sandoz at oracle.com
Fri May 18 18:39:45 UTC 2018


Hi Jason,

One of the rationals for adding “Predicate.not" is to avoid adding another stream operation, such as “reject" or “filterNot", and instead one can use "filter(not(String::isEmpty))” rather than “filter(s -> !s.isEmpty())” if so desired. (This was the reason why i did not close down the issue, and sat on it, and thankfully Jim took action.)

We are trying to avoid adding “overloaded" forms of the same kind of operation, such as in this case, or filtering classes, or filtering values etc.

Hth, Paul.

On May 18, 2018, at 11:22 AM, Jacob Glickman <jhg023 at bucknell.edu> wrote:

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