"Structural pattern matching" for Python, part 2
"Structural pattern matching" for Python, part 2
Posted Sep 6, 2020 11:35 UTC (Sun) by kleptog (subscriber, #1183)In reply to: "Structural pattern matching" for Python, part 2 by ecree
Parent article: "Structural pattern matching" for Python, part 2
An alternative to algebraic pattern matching is allowing extra conditional, like in elixir (which also offers algebraic matching). Then it could look like:
match size:
case (x,y) if x == y:
circle()
case (x,y):
ellipse()
The whole power of such a match statement is that you can match entire nested structures, which this PEP does offer. An optional extra if clause for the more fancy cases can help here.
The LWN site is currently under high scraper load, so comment display has been suppressed for anonymous users. If you are a human, you may read the comments by clicking the button below:
Note: you can avoid this step in the future by logging into your LWN account.
