Skip to content

Predicates

johnmcclean-aol edited this page Nov 22, 2016 · 3 revisions

Predicates

Predicates defines a number of predicates for filtering cyclops-react data structures and for pattern matching.

Examples

We can use Predicates to filter a Stream

import static com.aol.cyclops.util.function.Predicates.greaterThan;
   
Stream.of(1,2,3,100,200,300)
      .filter(greaterThan(10));
  
//Stream[100,200,300]

Predicates compose

import static com.aol.cyclops.util.function.Predicates.*;

ReactiveSeq.of(1,2,3).filter(anyOf(not(in(2,3,4)),in(1,10,20)));
ListX.of(1,2,3).filter(anyOf(not(greaterThan(2)),in(1,10,20)));
PStackX.of(1,2,3).filter(anyOf(not(greaterThanOrEquals(2)),in(1,10,20)));
QueueX.of(1,2,3).filter(anyOf(not(lessThan(2)),in(1,10,20)));
ReactiveSeq.of(1,2,3).filter(anyOf(not(lessThanOrEquals(2)),in(1,10,20)));
ReactiveSeq.of(1,2,3).filter(anyOf(not(eq(2)),in(1,10,20)));
Stream.of(Maybe.of(2)).filter(eqv(Eval.now(2)));
Maybe.of(2).filter(eqv(Eval.later(()->2)); //Maybe[2]

Clone this wiki locally