Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

Latest commit

 

History

History
37 lines (28 loc) · 1.43 KB

README.md

File metadata and controls

37 lines (28 loc) · 1.43 KB

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: