Vinegar is a set of small but highly reusable libraries. Vinegar libraries typically don't require any other libraries, but play nice with popular frameworks and libraries.
Add a Maven dependency on the vinegar library you need in pom.xml:
<dependency>
<groupId>be.sweetmustard.vinegar</groupId>
<artifactId>vinegar-pattern-matcher</artifactId>
<version>0.1.1</version>
</dependency>
The Pattern Matcher Vinegar is inspired by JDK enhancement proposal 305. It brings Pattern Matching to Java in the form of a DSL. Here's an example of the Pattern Matcher Vinegar in action:
import static be.sweetmustard.vinegar.matcher.MappingCondition.is;
Function<Shape, String> matcher = new PatternMatcher<Shape, String>()
.when(is(Circle.class))
.then(c -> "Circle with radius " + c.getRadius())
.when(is(Rectangle.class))
.then(r -> "Rectangle with width " + r.getWidth() + " and height " + r.getHeight())
.otherwise("Unknown shape");
String result = matcher.apply(new Rectangle(2, 5)); // Returns: Rectangle with width 2 and height 5
See also Pattern Matching for Java
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Michael Devloo - Pattern Matcher - Sweet Mustard
- Stijn Van Bael - Pattern Matcher - Sweet Mustard
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.txt file for details