https://github.com/ertgl/natch
Pattern matching library.
https://github.com/ertgl/natch
functional matching paradigm pattern python
Last synced: 9 months ago
JSON representation
Pattern matching library.
- Host: GitHub
- URL: https://github.com/ertgl/natch
- Owner: ertgl
- License: mit
- Created: 2020-05-24T11:44:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-04T02:24:11.000Z (over 5 years ago)
- Last Synced: 2025-04-06T09:29:57.472Z (9 months ago)
- Topics: functional, matching, paradigm, pattern, python
- Language: Python
- Homepage: https://natch.readthedocs.io
- Size: 32.2 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
### [Natch](#)
Pattern matching library.
[](https://pypi.org/project/natch/)
[](https://natch.readthedocs.io)
[](https://circleci.com/gh/ertgl/natch)
[](https://github.com/ertgl/natch)
[](LICENSE.txt)
---
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:**
````python
@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](https://natch.readthedocs.io/en/latest/guide/examples.html).
Natch can be installed and updated using [pip](https://pip.pypa.io/en/stable/quickstart/).
```bash
$ pip install -U natch
```
### [Troubleshooting](#troubleshooting)
- #### [RecursionError](#troubleshooting--recursion-error)
> 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](https://docs.python.org/3/library/sys.html#sys.setrecursionlimit) as necessary.