asteroid icon indicating copy to clipboard operation
asteroid copied to clipboard

object pattern matching with a subset of fields

Open lutzhamel opened this issue 3 years ago • 0 comments

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 avatar Jan 19 '23 19:01 lutzhamel