3 ms·
I'd love to see how code using your version compares to code using the OP's version. Got any similar examples?
by gizmo385 11y ago
I'd love to see how code using your version compares to code using the OP's version. Got any similar examples?
- subtenante 11y agoI use it especially for enums so it's like: MatchMap.of(someOptional, defaultValue) .whenEquals(MyEnum.VALUEX, v -> someFn(p1, p2)) .whenEquals(MyEnum.VALUEY, v -> otherFn(p1, p2)) .resolve();
- johnlcox 11y agoI haven't tried it with enums, but it should still be possible with Motif. I'll have to add some tests. match(enumValOpt) .when(some(eq(MyEnum.VALUEX))).then(() -> someFn(p1, p2)) .when(some(eq(MyEnum.VALUEY))).then(() -> otherFn(p1, p2)) .orElse(defaultValue) .doMatch(); It's a little longer than your example since there is support for more than just Optional, but it's pretty similar.