Execute a tail recursive function iteratively
Project description
tailrec
Provides a decorator tailrec which executes a tail recursive function iteratively
Installation
pip install tailrec
Usage
Decorate the target function with tailrec. The first argument of the function is a callable object representing a recursive call. Make sure to use this callable in combination with a return statement.
Example
from tailrec import tailrec
@tailrec
def factorial(f, n: int, accum: int = 1) -> int:
if n > 0:
return f(n - 1, accum * n)
else:
return accum
print(factorial(1_100))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tailrec-0.1.2.tar.gz.
File metadata
- Download URL: tailrec-0.1.2.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.11.3 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ae1cceb4f4e971cd994440b10e20559b4e81e2b0d72be62105dbe9444181310
|
|
| MD5 |
563f0a0b35e14449948a60ac16dffa34
|
|
| BLAKE2b-256 |
571263676a4f3df66d12a18c1701f628d469d401add1fdba9c28d7e08d410890
|
File details
Details for the file tailrec-0.1.2-py3-none-any.whl.
File metadata
- Download URL: tailrec-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.11.3 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfebe4a6883f67e4a5b8eaf2e29caccc989e7585743affec6d44833c2416b596
|
|
| MD5 |
996c95f70e238f6aaa70d45d290a4112
|
|
| BLAKE2b-256 |
820b086b4c8e551a985a54e2a461622925ad3df67436542606d0507eb69fbf48
|