Funny, I happened to code something just today very similar, but a lot lighter (just two classes, Match for consuming only, and MatchMap for mapping the optional. No when/get, just a when taking two parameters : the predicate and the mapping function. public class MatchMap { private final Optional opt; private final U defaultValue; private final AtomicReference result = new AtomicReference (); private MatchMap(Option…
I'd love to see how code using your version compares to code using the OP's version. Got any similar examples?
MatchMap.of(someOptional, defaultValue)
.whenEquals(MyEnum.VALUEX, v -> someFn(p1, p2))
.whenEquals(MyEnum.VALUEY, v -> otherFn(p1, p2))
.resolve();