Skip to content

object pattern matching with a subset of fields #231

Open
@lutzhamel

Description

@lutzhamel

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeatures that are directly related to the core tenet of Asteroid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions