"Useless Ruby sugar": Pattern matching (Pt. 2)
zverok.space
zverok.space
Useless Ruby sugar: Pattern matching - https://news.ycombinator.com/item?id=37957189 - Oct 2023 (48 comments)
>
> events.select { _1 => type:, role:; type == 'create' || role == 'admin' }
I'd actually recommend using in instead:
events.select { _1 in {type: 'create'} | {role: 'admin'} }
I really enjoy using in for filtering. But I get the OP's point.Pattern matching does need QOL improvements to really feel like it's a first-class citizen of the language ... like patterning matching for method and block arguments. :)
It is one of the things I always enjoyed and tried to achieve myself (when the discussion of design decisions in one language would provide food for thought in the context of other languages/domains).