public interface Matchable<TYPE>
then(Supplier)
when(Predicate)
otherwise(Supplier)
Matchables} for precanned structural pattern matching against JDK classes
Use Matchable#of or Matchable#matchable (an alias for use with static imports) to pattern match via guards on an Object.
Matchable supports tail recursion
{@code
import static com.aol.cyclops.control.Matchable.matchable;
Modifier and Type | Interface and Description |
---|---|
static class |
Matchable.AsMatchable |
static class |
Matchable.AutoCloseableMatchableIterable<TYPE> |
static class |
Matchable.CheckValue1<T,R> |
static class |
Matchable.CheckValue2<T1,T2,R> |
static class |
Matchable.CheckValue3<T1,T2,T3,R> |
static class |
Matchable.CheckValue4<T1,T2,T3,T4,R> |
static class |
Matchable.CheckValue5<T1,T2,T3,T4,T5,R> |
static class |
Matchable.CheckValueOpt<T,R> |
static class |
Matchable.CheckValues<T,R> |
static interface |
Matchable.MatchableIterable<TYPE> |
static interface |
Matchable.MatchableObject<TYPE> |
static interface |
Matchable.MatchableOptional<T> |
static interface |
Matchable.MatchSelf<TYPE> |
static interface |
Matchable.MTuple1<T1> |
static interface |
Matchable.MTuple2<T1,T2> |
static interface |
Matchable.MTuple3<T1,T2,T3> |
static interface |
Matchable.MTuple4<T1,T2,T3,T4> |
static interface |
Matchable.MTuple5<T1,T2,T3,T4,T5> |
static interface |
Matchable.MXor<T1,T2> |
static interface |
Matchable.ValueAndOptionalMatcher<T> |
Modifier and Type | Method and Description |
---|---|
static <T> Matchable.MTuple1<T> |
matchable(T o)
Match on the supplied Object
|
static <T> Matchable.MatchableObject<T> |
of(java.util.stream.Stream<T> o)
Create a new matchable that will match on the fields of the provided Stream
|
static <T> Matchable.MTuple1<T> |
of(T o)
Create a new matchable that will match on the fields of the provided Object
|
static <R> java.util.function.Supplier<R> |
otherwise(R value) |
static <R> java.util.function.Supplier<R> |
otherwise(java.util.function.Supplier<? extends R> s) |
static <T,R> java.util.function.Supplier<? extends R> |
then(R value)
Matchable DSL operator for outcomes
|
static <T,R> java.util.function.Supplier<? extends R> |
then(java.util.function.Supplier<? extends R> fn) |
static <T1> Matchable.MTuple1<java.util.function.Predicate<? super T1>> |
when(java.util.function.Predicate<? super T1> t1) |
static <T1,T2,T3> Matchable.MTuple2<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>> |
when(java.util.function.Predicate<? super T1> t1,
java.util.function.Predicate<? super T2> t2) |
static <T1,T2,T3> Matchable.MTuple3<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>,java.util.function.Predicate<? super T3>> |
when(java.util.function.Predicate<? super T1> t1,
java.util.function.Predicate<? super T2> t2,
java.util.function.Predicate<? super T3> t3) |
static <T1,T2,T3,T4> |
when(java.util.function.Predicate<? super T1> t1,
java.util.function.Predicate<? super T2> t2,
java.util.function.Predicate<? super T3> t3,
java.util.function.Predicate<? super T4> t4) |
static <T1,T2,T3,T4,T5> |
when(java.util.function.Predicate<? super T1> t1,
java.util.function.Predicate<? super T2> t2,
java.util.function.Predicate<? super T3> t3,
java.util.function.Predicate<? super T4> t4,
java.util.function.Predicate<? super T5> t5) |
static <T1> Matchable.MTuple1<java.util.function.Predicate<? super T1>> |
when(T1 t1) |
static <T1,T2> Matchable.MTuple2<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>> |
when(T1 t1,
T2 t2) |
static <T1,T2,T3> Matchable.MTuple3<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>,java.util.function.Predicate<? super T3>> |
when(T1 t1,
T2 t2,
T3 t3) |
static <T1,T2,T3,T4> |
when(T1 t1,
T2 t2,
T3 t3,
T4 t4) |
static <T1,T2,T3,T4,T5> |
when(T1 t1,
T2 t2,
T3 t3,
T4 t4,
T5 t5) |
static <T,V> Matchable.MTuple1<java.util.function.Predicate<? super T>> |
whenGuard(V... values) |
static <T,V> java.lang.Iterable<java.util.function.Predicate<? super T>> |
whenGuard2(V... values) |
static <T1> java.lang.Iterable<java.util.function.Predicate<? super T1>> |
whenTrue(java.util.function.Predicate<? super T1>... t1) |
static <T1> java.lang.Iterable<java.util.function.Predicate<? super T1>> |
whenValues(T1... t1) |
static <T> Matchable.MTuple1<T> matchable(T o)
Matchable.matchable(100)
.matches(c->c.is(when(greaterThan(50)), ()->"large"), ()->"small");
//Eval["large"]
For a structural equivalent, matching on a single object @see Matchables.match(Object)
o
- static <T> Matchable.MTuple1<T> of(T o)
import static com.aol.cyclops.util.function.Predicates.__;
import static com.aol.cyclops.control.Matchable.whenGuard;
import static com.aol.cyclops.util.function.Predicates.has;
Matchable.of(new NestedCase(1,2,new NestedCase(3,4,null)))
.matches(cases->cases.is(whenGuard(1,__,has(3,4,__)),then("2")),otherwise("4"))
o
- Object to match on it's fieldsstatic <T> Matchable.MatchableObject<T> of(java.util.stream.Stream<T> o)
o
- Object to match on it's fieldsstatic <T,R> java.util.function.Supplier<? extends R> then(R value)
value
- static <T,R> java.util.function.Supplier<? extends R> then(java.util.function.Supplier<? extends R> fn)
static <R> java.util.function.Supplier<R> otherwise(R value)
static <R> java.util.function.Supplier<R> otherwise(java.util.function.Supplier<? extends R> s)
@SafeVarargs static <T,V> java.lang.Iterable<java.util.function.Predicate<? super T>> whenGuard2(V... values)
@SafeVarargs static <T,V> Matchable.MTuple1<java.util.function.Predicate<? super T>> whenGuard(V... values)
static <T1> java.lang.Iterable<java.util.function.Predicate<? super T1>> whenValues(T1... t1)
static <T1> java.lang.Iterable<java.util.function.Predicate<? super T1>> whenTrue(java.util.function.Predicate<? super T1>... t1)
static <T1> Matchable.MTuple1<java.util.function.Predicate<? super T1>> when(T1 t1)
static <T1> Matchable.MTuple1<java.util.function.Predicate<? super T1>> when(java.util.function.Predicate<? super T1> t1)
static <T1,T2> Matchable.MTuple2<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>> when(T1 t1, T2 t2)
static <T1,T2,T3> Matchable.MTuple2<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>> when(java.util.function.Predicate<? super T1> t1, java.util.function.Predicate<? super T2> t2)
static <T1,T2,T3> Matchable.MTuple3<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>,java.util.function.Predicate<? super T3>> when(T1 t1, T2 t2, T3 t3)
static <T1,T2,T3> Matchable.MTuple3<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>,java.util.function.Predicate<? super T3>> when(java.util.function.Predicate<? super T1> t1, java.util.function.Predicate<? super T2> t2, java.util.function.Predicate<? super T3> t3)
static <T1,T2,T3,T4> Matchable.MTuple4<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>,java.util.function.Predicate<? super T3>,java.util.function.Predicate<? super T4>> when(T1 t1, T2 t2, T3 t3, T4 t4)
static <T1,T2,T3,T4> Matchable.MTuple4<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>,java.util.function.Predicate<? super T3>,java.util.function.Predicate<? super T4>> when(java.util.function.Predicate<? super T1> t1, java.util.function.Predicate<? super T2> t2, java.util.function.Predicate<? super T3> t3, java.util.function.Predicate<? super T4> t4)
static <T1,T2,T3,T4,T5> Matchable.MTuple5<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>,java.util.function.Predicate<? super T3>,java.util.function.Predicate<? super T4>,java.util.function.Predicate<? super T5>> when(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
static <T1,T2,T3,T4,T5> Matchable.MTuple5<java.util.function.Predicate<? super T1>,java.util.function.Predicate<? super T2>,java.util.function.Predicate<? super T3>,java.util.function.Predicate<? super T4>,java.util.function.Predicate<? super T5>> when(java.util.function.Predicate<? super T1> t1, java.util.function.Predicate<? super T2> t2, java.util.function.Predicate<? super T3> t3, java.util.function.Predicate<? super T4> t4, java.util.function.Predicate<? super T5> t5)