/matcha

Fluent, Scala-like pattern matching in pure Java using Java 8's functional additions.

Primary LanguageJavaMIT LicenseMIT

Matcha

matcha

Build Status Coverage Status Maintainability

Fluent pattern matching for Java.

Matcha is an library providing a pattern-matching system for Java. It primarily focuses on being fluent, concise, and extendable.

Example

public class NumberDescriber {
    public static String describeNumber(Number number) {
        return when(number).matchedTo(String.class)
                .is(Double.class).then(i -> i + " is a double.")
                .matches(n -> (n.intValue() & 1) != 0).then(i -> i + " is odd.")
                .matches(42).then("42 is an interesting number.")
                .otherwise(n -> "I don't have much to say about " + n + ".");
    }
}

See also

Here are some other interesting projects that also implement pattern matching in Java: