Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/magniff/endless
Stack overflow freedom
https://github.com/magniff/endless
recursion stack trampoline
Last synced: 12 days ago
JSON representation
Stack overflow freedom
- Host: GitHub
- URL: https://github.com/magniff/endless
- Owner: magniff
- Created: 2015-10-31T13:58:29.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-19T22:52:29.000Z (about 8 years ago)
- Last Synced: 2024-09-18T03:00:41.889Z (about 2 months ago)
- Topics: recursion, stack, trampoline
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ENDLESS
[![Build Status](https://api.travis-ci.org/magniff/endless.svg?branch=master)](https://travis-ci.org/magniff/endless)## WTF
This tiny library helps you to write recursive functions without any ''stack overflow'' related pain.Say you have a function like this:
```python
def factorial(value):
return 1 if value == 1 else value * factorial(value-1)
```
It works fine until the ```value``` thing is less then a ```sys.getrecursionlimit()```.ENDLESS provides a solution
```python
@endless.make
def factorial(value):
return 1 if value == 1 else value * (yield {'value': value-1})
```and then you can use it as a normal function:
``` python
>>> result = factorial(10000)
```This decorated function is completely stack overflow free, because it doesn't use process's stack section at all.
Also stuff like this one is also possible (called maccarthy91 function):
```python
@endless.make
def maccarthy(value):
if value > 100:
return value - 10
else:
return (yield {'value': (yield {'value': value+11})})
```
#### So the rule is that: whenever you want to use a recursive call, just yield the dictionary, representing the function kwargs, that is it.## INSTALLATION
```python
pip install endless
```