Java 8 lambda predicate chaining?

java, java-8, lambda

Solution

You can use:

((Predicate<String>) e -> e.equals("1")).or(e -> e.equals("2"))

but it's not very elegant. If you're specifying the conditions in-line, just use one lambda:

e -> e.equals("1") || e.equals("2")

Problem

I can't get it to compile, is it even possible to chain predicate lambdas? ``` Arrays.asList("1","2","3").stream().filter( (e -> e=="1" ).or(e-> e=="2") ).count(); ``` Or only way is to explicitly create a predicate and then combine like so: ``` Predicate<String> isOne= e -> e=="1"; Arrays.asList("1","2","3").stream().filter( isOne.or(e -> e=="2") ).count(); ``` Or is there more "functionally elegant" way to achieve same thing?

Original source