Pattern matching library.
Natch enables, but is not limited to, pattern matching in function headers with single or multi arities, by supporting linear or nested lookups including logical expressions; can be expanded by writing custom rule classes.
Conditional function headers:
@natch.lt(0)
def f(x):
return f(x * -1)
@natch.gte(0)
def f(x):
return x + 1
>>> f(-1)
>>> 2
See more examples.
Natch can be installed and updated using pip.
$ pip install -U natch
Python has a platform-dependent recursion limit. If your software requires too many nested function calls, it is recommended to avoid using recursive functions.
If you still need to follow recursive approach, you may need to set recursion limit as necessary.