PHPackages                             starship/tailrecursion - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. starship/tailrecursion

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

starship/tailrecursion
======================

Tail Recursion Class

04PHP

Since Feb 23Pushed 12y ago1 watchersCompare

[ Source](https://github.com/evan108108/TailRecursion)[ Packagist](https://packagist.org/packages/starship/tailrecursion)[ RSS](/packages/starship-tailrecursion/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

TailRecursion
=============

[](#tailrecursion)

Tail-Recursion class for php 5.4 or greater

Inspired by [beberlei](https://gist.github.com/beberlei/4145442)

Install
-------

[](#install)

The recommended way to install react/tailrecursion is [through composer](http://getcomposer.org).

```
{
    "require": {
        "starship/tailrecursion": "dev-master"
    }
}
```

Examples
--------

[](#examples)

```
use \Starship\TailRecursion\TailRecursion as tr;

echo tr::init(function($n, $acc = 1) {
    if ($n == 1) {
        return $acc;
    }
    return $this->tail($n - 1, $acc * $n);
})->run(4);  // 1 * 2 * 3 * 4 = 24
```

```
use \Starship\TailRecursion\TailRecursion as tr;

$flatList = tr::init(function($list, $acc=[]) {
	if(count($list) < 1) {
		return $acc;
	}
	if(is_array($result = array_shift($list))) {
		 return $this->tail(array_merge($result, $list), $acc);
	}
	$acc[] = $result;
	return $this->tail($list, $acc);
});

//Will output [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print_r($flatList->run([1,[2,3],[4,[5]],[6], [7,[8,9],10]], [0]));
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/801e92d75e08f2a39f32c6c3b40cd8f6e71c0ddc145812bb389b0359dc832be8?d=identicon)[evan108108](/maintainers/evan108108)

---

Top Contributors

[![evan108108](https://avatars.githubusercontent.com/u/197995?v=4)](https://github.com/evan108108 "evan108108 (5 commits)")

### Embed Badge

![Health badge](/badges/starship-tailrecursion/health.svg)

```
[![Health](https://phpackages.com/badges/starship-tailrecursion/health.svg)](https://phpackages.com/packages/starship-tailrecursion)
```

###  Alternatives

[nystudio107/richvariables

Allows you to easily use Craft Globals as variables in Rich Text fields

441.5k](/packages/nystudio107-richvariables)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
