Registered
by
Martin Morrison
A library that brings Scala-like pattern matching to Python.
Example use case:
caseclass.Sum(“l”, “r”)
caseclass.Var(“n”)
caseclass.
def evaluate(t, env):
return t.match(
case[Sum] >> (lambda l, r: evaluate(l, env) + evaluate(r, env)),
case[Var] >> (lambda n: env[n]),
case[Const] >> (lambda v: v),
)
# Let’s calculate: (x + x) + (7 + y)
tree = Sum(Sum(Var(x), Var(x)), Sum(Const(7), Var(y)))
evaluate(tree, {"x”: 5, "y”: 6}) # == 23
Project information
- Maintainer:
- Martin Morrison
- Driver:
- Martin Morrison
- Licence:
- Simplified BSD Licence
View full history Series and milestones
Loading graph...
motif series is the current focus of development.