On the case of single-line match statements

I’m liking this matches operator a lot. It is indeed a more elegant solution to Expand structural pattern matching-like syntax to assignments/generalized unpacking that I proposed a while back.

And thanks for putting together some good usage examples. Like @ncoghlan pointed out, the usefulness of such an operator is most apparent as a while loop condition, making the intent of the loop that much more immediately understood than an equivalent while True: match ...: case ...: if ...: break.

Great example here as well. Embedding the matches expression in a filter of a list comprehension reads better than an equivalent for loop with a match-case statement conditionally appending to a list IMHO.

To be sure, this operator is syntax sugar just like comprehensions are. But good syntax sugar can help convey the intent of code logics better than equivalent primitive constructs when used in right places.

I hope this can gain more support from the devs.

2 Likes