Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 835 Bytes

README.md

File metadata and controls

39 lines (30 loc) · 835 Bytes

java pattern matching

  • Boolean match
        Matchers.match(true)
                .then(() -> {
                    assert true;
                })
                .otherwise(() -> {
                    assert false;
                });

        int value = Matchers.match(false)
                .then(() -> 1)
                .otherwise(2)
                .result();
        assert value == 2;
  • any match
        Integer case = Matchers.of("11")
                .match("22").then(1)
                .match("11").then(() -> null)
                .match("11").then(3)
                .defaultThen(4)
                .result();
        assert case == 4;

        Integer case2 = Matchers.of("11")
                .match("22").then(1)
                .result();
        assert Objects.isNull(case2);