Skip to content

Support for pattern matching (Ruby 2.7+) #227

@kputnam

Description

@kputnam

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions