public interface Matchable
| Modifier and Type | Method and Description |
|---|---|
default <R,I> R |
_match(java.util.function.Function<CheckTypeAndValues<I>,MatchingInstance> fn)
Match against this matchable using algebraic matching interface (each field can
be matched individually).
|
default <R,I> R |
_match(java.util.function.Function<CheckTypeAndValues<I>,MatchingInstance> fn,
R defaultValue)
Match against this matchable using algebraic matching interface (each field can
be matched individually).
|
default java.lang.Object |
getMatchable() |
default <R,T,I> R |
match(java.util.function.Function<CheckValues<I,T>,CheckValues<I,T>> fn)
new MyCase(1,2,3).matchValues(this::choseMessage)
private <I,T> CheckValues<Object, T> chooseMessage(CheckValues<I, T> c) {
return c.with(1,2,3).then(i->"hello")
.with(4,5,6).then(i->"goodbye");
}
\@Value static class MyCase implements Matchable{ int a; int b; int c; }
|
default <R,T,I> R |
match(java.util.function.Function<CheckValues<I,T>,CheckValues<I,T>> fn,
R defaultValue) |
default <R> R |
matchType(java.util.function.Function<CheckType<? super R>,CheckType<? super R>> fn)
Match against this matchable using simple matching interface
|
default <R> R |
matchType(java.util.function.Function<CheckType<? super R>,CheckType<? super R>> fn,
R defaultValue)
Match against this matchable using simple matching interface
|
default java.lang.Object getMatchable()
default <R,T,I> R match(java.util.function.Function<CheckValues<I,T>,CheckValues<I,T>> fn)
new MyCase(1,2,3).matchValues(this::choseMessage)
private <I,T> CheckValues<Object, T> chooseMessage(CheckValues<I, T> c) {
return c.with(1,2,3).then(i->"hello")
.with(4,5,6).then(i->"goodbye");
}
\@Value static class MyCase implements Matchable{ int a; int b; int c; }
fn - default <R,T,I> R match(java.util.function.Function<CheckValues<I,T>,CheckValues<I,T>> fn, R defaultValue)
default <R> R matchType(java.util.function.Function<CheckType<? super R>,CheckType<? super R>> fn)
return match(c ->
c.caseOf( (Put p) -> new Put(p.key,p.value,(Action)fn.apply(p.next)))
.caseOf((Delete d) -> new Delete(d.key,(Action)fn.apply(d.next)))
.caseOf((Get g) -> new Get(g.key,(Function)g.next.andThen(fn)))
);
fn - Function to build the matching expressiondefault <R> R matchType(java.util.function.Function<CheckType<? super R>,CheckType<? super R>> fn, R defaultValue)
return match(c ->
c.caseOf( (Put p) -> new Put(p.key,p.value,(Action)fn.apply(p.next)))
.caseOf((Delete d) -> new Delete(d.key,(Action)fn.apply(d.next)))
.caseOf((Get g) -> new Get(g.key,(Function)g.next.andThen(fn)))
noOperation()
);
fn - Function to build the matching expressiondefaultValue - Default value if matching expression does not matchdefault <R,I> R _match(java.util.function.Function<CheckTypeAndValues<I>,MatchingInstance> fn)
fn - Function to build the matching expressiondefault <R,I> R _match(java.util.function.Function<CheckTypeAndValues<I>,MatchingInstance> fn, R defaultValue)
fn - Function to build the matching expressiondefaultValue - Default value if matching expression does not match