Metadata-Version: 2.3
Name: tailrec
Version: 0.1.3
Summary: Execute a tail recursive function iteratively
License: MIT
Author: Christian Kreutz
Author-email: christian.kreutz.dev@stud.uni-due.de
Requires-Python: >=3.11
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Project-URL: Repository, https://github.com/chr3st5an/tailrec
Description-Content-Type: text/markdown

# tailrec

Provides a decorator `tailrec` which executes a tail recursive function iteratively

## Installation

```bash
pip install tailrec
```

## Examples

```py
from tailrec import tailrec


@tailrec
def factorial(n: int, accum: int = 1) -> int:
    """Calculates n!"""
    if n == 0:
        return accum
    else:
        return factorial(n - 1, accum * n)


@tailrec
def fibonacci(n: int, current: int = 0, next_: int = 1) -> int:
    """Returns the n-th number of the fibonacci sequence"""
    if n == 0:
        return current
    else:
        return fibonacci(n - 1, next_, current + next_)


print(factorial(5))  # 120
print(factorial(1_100))  # 5343708488092637703...

print(fibonacci(5))  # 8
print(fibonacci(2_000))  # 42246963333923...
```

