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

lifting matching variables from patterns in case #1370

Open
Licenser opened this issue Dec 15, 2021 · 0 comments
Open

lifting matching variables from patterns in case #1370

Licenser opened this issue Dec 15, 2021 · 0 comments
Labels
_complexity:high A task with a high complexity that should be hard enhancement New feature or request language needs-rfc This change needs to follow the RFC process _size:medium A medium sized task that will take some time to complete

Comments

@Licenser
Copy link
Member

Describe the problem you are trying to solve

We often have the situation where we match and extract data in a case clause, this data is stored in a nested fashion which can feel cumbersome to use and is possibly unintuitive that keys assigned in a record are not accessible as varaibles.

Describe the solution you'd like

A match form that lifts up the matched keys into local variables inside the catch so they can be accessed directly, for example (syntax here being a quick make up):

match event of
  # without lifting variables (current code)
  case res ~= %{present method, url ~= re|http://(?P<host>.*?)/(?P<path>.*)|} => "We are ${res.method}ing ${res.patrh} from host ${res.host}"
  # with lifting variables
  case ^ %{present method, url ~= re|http://(?P<host>.*?)/(?P<path>.*)|} => "We are ${method}ing ${patrh} from host ${host}"
end

Notes
An additional upside is that we would save the cost of creating and then deconstructing a record result making the lifted form a more performant option.

@Licenser Licenser added enhancement New feature or request language _complexity:high A task with a high complexity that should be hard _size:medium A medium sized task that will take some time to complete labels Dec 15, 2021
@darach darach added the needs-rfc This change needs to follow the RFC process label May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
_complexity:high A task with a high complexity that should be hard enhancement New feature or request language needs-rfc This change needs to follow the RFC process _size:medium A medium sized task that will take some time to complete
Projects
None yet
Development

No branches or pull requests

2 participants