Pattern Matching for Python 3.7+ in a simple, yet powerful, extensible manner.
Some
is now properly HashableParameters
Arguments
_
(underscore) special key pattern when matching dictionarieswhen=
and guarded
)Remainder
Object
This allows
Some(*)
to match subsequences.Previously
Some(...)
would only match individiual items, i.e. the pattern[0, Some(1), 2]
would match the value[0, 1, 1, 1, 2]
. Compared with a regex on strings this would be like01*2
but the repetition here could not be applied to subsequences0(12)*3
. This pull request introduces the ability forSome(*)
to take multiple patterns which it then tries to match as a sequence within:[0, Some(1, 2), 3]
would now match the value[0, 1, 2, 1, 2, 3]
. This could not be expressed before.Note that the new syntax is different from
Some([1, 2])
as this would match items which are themselves lists, i.e.[0, [1, 2], [1, 2], 3]
.
Fixes #2
Released as https://pypi.org/project/awesome-pattern-matching/0.21.2/
.explain()
which can help with understanding why a match did not succeed