-
Notifications
You must be signed in to change notification settings - Fork 136
Matchables
johnmcclean-aol edited this page Nov 21, 2016
·
2 revisions
The Matchables class provides a large number of methods for structural pattern matching on common JDK and cyclops-react type - for example to match on a URL
import static com.aol.cyclops.control.Matchable.when;
import static com.aol.cyclops.control.Matchable.then;
import static com.aol.cyclops.control.Matchable.otherwise;
Eval<String> url = Matchables.url(new URL("http://www.aol.com/path?q=hello"))
.on$12_45()
.matches(c->c.is(when("http","www.aol.com","/path","q=hello"), then("correct")),otherwise("miss"));
//Eval["correct"]
import static com.aol.cyclops.control.Matchable.when;
import static com.aol.cyclops.control.Matchable.then;
import static com.aol.cyclops.control.Matchable.otherwise;
Eval<Integer> result = Matchables.future(FutureW.ofResult(1))
.matches(c-> c.is( when(some(1)), then(10)),
c->c.is(when(instanceOf(RuntimeException.class)), then(2)),
otherwise(3));
//Eval.now[10]
Eval<Integer> result = Matchables.future(FutureW.ofError(new RuntimeException()))
.matches(c-> c.is( when(some(10)), then(2)),
c->c.is(when(instanceOf(RuntimeException.class)), then(2)),
otherwise(3));
//Eval.now(2)
oops - my bad