Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for pattern matching (Ruby 2.7+) #227

Open
kputnam opened this issue Jul 21, 2020 · 0 comments
Open

Support for pattern matching (Ruby 2.7+) #227

kputnam opened this issue Jul 21, 2020 · 0 comments
Labels

Comments

@kputnam
Copy link
Owner

kputnam commented Jul 21, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant