stupidedi icon indicating copy to clipboard operation
stupidedi copied to clipboard

Support for pattern matching (Ruby 2.7+)

Open kputnam opened this issue 3 years ago • 0 comments

Ruby 2.7 introduces pattern matching, which could make the API nicer for users. From what I've read, we can support this by implementing #=== and #deconstruct and/or #deconstruct_keys on data types. We have a number of classes like Either, Result, and AbstractCursor that might be good candidates for this. These are abstract classes that imitate algebraic data types.

I would like to be able to hide some constructor parameters though, if for example, they are irrelevant to users or the parameters cannot be easily provided. This may be possible using #deconstruct_keys, though I'm not sure if it's possible to specify the expected class using that syntax. Another option would be to attempt to emulate Haskell's view patterns or Scala's extractor objects.

For now, I won't begin working on this until other changes are completed and released, but it will eventually happen.

kputnam avatar Jul 21 '20 06:07 kputnam