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

object pattern matching with a subset of fields #231

Open
lutzhamel opened this issue Jan 19, 2023 · 0 comments
Open

object pattern matching with a subset of fields #231

lutzhamel opened this issue Jan 19, 2023 · 0 comments
Labels
enhancement Features that are directly related to the core tenet of Asteroid

Comments

@lutzhamel
Copy link
Collaborator

lutzhamel commented Jan 19, 2023

It is often convenient to express a pattern match on an object based only on a single field like

structure Person with
   data name.
   data age.
   data profession.
end

let people = [
   Person("Joe", 32, "Carpenter").
   Person("Darlene", 26, "Developer").
   Person("Peter", 35, "Cook")
]

let cnt = 0.
for Person(*) match age if age > 30 in people do
   let cnt = cnt+1.
end

Instead of

for Person(_,age if age > 30,_) in people do...

or

for (x:%Person) if x@age > 30 in people do...
@lutzhamel lutzhamel added the enhancement Features that are directly related to the core tenet of Asteroid label Feb 17, 2023
@lutzhamel lutzhamel added this to the Release 2.0.0 milestone Apr 7, 2023
@lutzhamel lutzhamel removed this from the Release 2.0.1 milestone May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Features that are directly related to the core tenet of Asteroid
Projects
None yet
Development

No branches or pull requests

1 participant