summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/patterns/IPatternMatcher.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2020-12-14 19:29:37 -0400
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2020-12-14 19:29:37 -0400
commit9351ea3e97bbe2d348aa17067ccc6267dc7c080f (patch)
treedd2269c26161c735d94d8dc83d56e6076c2a155d /base/src/main/java/bjc/utils/patterns/IPatternMatcher.java
parent8933de7f646f0565edf700aa2f2fcab06d639855 (diff)
parent6dcadc360dafdd12142d53327f44579379a4c9dd (diff)
Merge branch 'master' of https://github.com/bculkin2442/bjc-utils2
Diffstat (limited to 'base/src/main/java/bjc/utils/patterns/IPatternMatcher.java')
-rw-r--r--base/src/main/java/bjc/utils/patterns/IPatternMatcher.java85
1 files changed, 0 insertions, 85 deletions
diff --git a/base/src/main/java/bjc/utils/patterns/IPatternMatcher.java b/base/src/main/java/bjc/utils/patterns/IPatternMatcher.java
deleted file mode 100644
index b688a47..0000000
--- a/base/src/main/java/bjc/utils/patterns/IPatternMatcher.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package bjc.utils.patterns;
-
-import java.util.function.*;
-
-import bjc.functypes.*;
-
-/**
- * Represents a pattern matcher against a series of patterns.
- *
- * @author Ben Culkin
- *
- * @param <ReturnType> The type returned from matching the patterns.
- * @param <InputType> The type to match against.
- */
-@FunctionalInterface
-public interface IPatternMatcher<ReturnType, InputType> {
- /**
- * Match an input object against a set of patterns.
- *
- * @param input The object to match against.
- *
- * @return The result of matching against the object.
- *
- * @throws NonExhaustiveMatch If none of the patterns in this set match
- */
- ReturnType matchFor(InputType input) throws NonExhaustiveMatch;
-
- /**
- * Create a pattern matcher against a static set of patterns.
- *
- * @param <RetType> The type returned from matching the patterns.
- * @param <InpType> The type to match against.
- *
- * @param patterns The set of patterns to match on.
- *
- * @return A pattern matcher which matches on the given patterns.
- */
- @SafeVarargs
- static <RetType, InpType> IPatternMatcher<RetType, InpType> matchingOn(
- ComplexPattern<RetType, ?, InpType>... patterns) {
- return new PatternMatcher<>(patterns);
- }
-
- /**
- * Create a pattern matcher from a handler function.
- *
- * @param <RetType> The type returned by the matcher.
- * @param <InpType> The type to match against.
- *
- * @param handler The handler function.
- *
- * @return A pattern matcher defined by the given handler.
- */
- static <RetType, InpType> IPatternMatcher<RetType, InpType> from(
- ThrowFunction<InpType, RetType, NonExhaustiveMatch> handler) {
- return new FunctionalPatternMatcher<>(handler);
- }
-
- /**
- * Create a pattern matcher which applies a transform to its input.
- *
- * @param <NewInput> The new input type to use.
- * @param transformer The function to convert from the new input to the old input.
- *
- * @return A pattern matcher which takes values of the new type instead.
- */
- default <NewInput> IPatternMatcher<ReturnType, NewInput> transformInput(
- Function<NewInput, InputType> transformer) {
- return from(inp -> matchFor(transformer.apply(inp)));
- }
-
- /**
- * Create a pattern matcher which applies a transform to its output.
- *
- * @param <NewOutput> The new output type to use.
- *
- * @param transformer The function to convert from the new output to the old output.
- *
- * @return A pattern matcher which takes values of the new type instead.
- */
- default <NewOutput> IPatternMatcher<NewOutput, InputType> transformOutput(
- Function<ReturnType, NewOutput> transformer) {
- return from(inp -> transformer.apply(matchFor(inp)));
- }
-} \ No newline at end of file