Closed serras closed 3 months ago
Total Project Coverage | 60.80% |
---|
Cool stuff! Never actually used Optics for pattern matching, knew it was theoretically possible. Can we also supports sealed classes through Prism
?
Can we also supports sealed classes through
Prism
?
We do! It's there in the example :P
Oh yes, of course! It's relying on Prism : Optional
π
Wow, that is so cool! π π π
Haven't taken a full look at the PR yet, but this should definitely have an integration with SingletonRaise so that it fails similarly to Monad.fail from Haskell
I've just pushed a new commit which I think covers both of your comments:
matchOrElse
, which gets an additional argument telling what to do if no match is found;matchOrThrow
, matchOrRaise
, and matchUnit
are derived.I like the possibility of having a catch-all case within the DSL, since it mirrors how one usually defines pattern matching.
value.match {
User.company.address(Address.street) then { s -> ... }
default { "Unknown address " }
}
I like the possibility of having a catch-all case within the DSL, since it mirrors how one usually defines pattern matching.
Yes, that looks great, but I felt that the strategy should be explicit in the function names. Thank you, great improvement!
Late to the party but wanted to say this looks great π
This PR proposes a small DSL to describe pattern matching. This is based on three ideas:
Optional
s in a row,Optional<S, A> + Optional<S, B> = Optional<S, Pair<A, B>>
invoke
to simulate them.This is an example from the code. Note that
then
separates an optional that matches and the code that uses the information being matched as result.