You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing pattern-matching functions using matchWith, it is possible to not cover all the variants of a union. Since of course we cannot statically verify all cases of a pattern match are covered, this error occurs at runtime. Currently, attempting to match on a missing variant results in a generic error. I think it would be useful to have a more specific error that tells us what variant we need to add to the matchWith pattern.
I'm more than happy to submit a pull request with this small change if you think it would be useful!
Steps to reproduce
import{union}from'folktale/adt/union'constOperation=union({Add: (a,b)=>({ a, b }),Subtract: (a,b)=>({ a, b }),})// evaluate : Operation -> Intconstevaluate=op=>op.matchWith({Add: ({ a, b })=>a+b// Subtract not implemented!})evaluate(Operation.Subtract(3,4))
Expected behaviour
Error like Variant "Subtract" not covered in pattern
Observed behaviour
Error like TypeError: pattern[name] is not a function
Environment
Folktale v2.0.0-rc1
The text was updated successfully, but these errors were encountered:
When writing pattern-matching functions using
matchWith
, it is possible to not cover all the variants of a union. Since of course we cannot statically verify all cases of a pattern match are covered, this error occurs at runtime. Currently, attempting to match on a missing variant results in a generic error. I think it would be useful to have a more specific error that tells us what variant we need to add to thematchWith
pattern.I'm more than happy to submit a pull request with this small change if you think it would be useful!
Steps to reproduce
Expected behaviour
Error like
Variant "Subtract" not covered in pattern
Observed behaviour
Error like
TypeError: pattern[name] is not a function
Environment
Folktale v2.0.0-rc1
The text was updated successfully, but these errors were encountered: