PHPackages                             improved/function - 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. improved/function

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

improved/function
=================

Function handling and functional programming

v1.0.0(1y ago)4106.7k↓23.1%2MITPHPPHP &gt;=8.1.0

Since Oct 17Pushed 1y agoCompare

[ Source](https://github.com/jasny/improved-php-function)[ Packagist](https://packagist.org/packages/improved/function)[ RSS](/packages/improved-function/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (5)Used By (2)

[![improved PHP library](https://user-images.githubusercontent.com/100821/46372249-e5eb7500-c68a-11e8-801a-2ee57da3e5e3.png)](https://user-images.githubusercontent.com/100821/46372249-e5eb7500-c68a-11e8-801a-2ee57da3e5e3.png)

function handling
=================

[](#function-handling)

[![PHP](https://github.com/jasny/improved-php-function/workflows/PHP/badge.svg)](https://github.com/jasny/improved-php-function/workflows/PHP/badge.svg)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4465a9f680107b1b117feb4e95bab54008ed8fe649cb9f60762d079bf3aa40cd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61736e792f696d70726f7665642d7068702d66756e6374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/improved-php-library/function/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/b871e07fc555ca02c62ea994ae60de0f3b3d37e2d7b1e02e5dd1b360649040e0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61736e792f696d70726f7665642d7068702d66756e6374696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/improved-php-library/function/?branch=master)[![Packagist Stable Version](https://camo.githubusercontent.com/1e35214f254b346e415b101773179d0ac5165350b80e1841fbc5a72557291a3c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d70726f7665642f66756e6374696f6e2e737667)](https://packagist.org/packages/improved/function)[![Packagist License](https://camo.githubusercontent.com/1ba6815e3b3a2095bebc29383b10d4821fb3dbbf26c58c5a810c100ca9dbcd28/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696d70726f7665642f66756e6374696f6e2e737667)](https://packagist.org/packages/improved/function)

Library for function handling and functional programming.

Installation
------------

[](#installation)

```
composer require improved/function

```

Functions
---------

[](#functions)

- [`function_pipe(callable ...$callables)`](#function_pipe)
- [`function_all(callable ...$callables)`](#function_all)
- [`function_trampoline(callable $callable)`](#function_tail_recursion)

### function\_pipe

[](#function_pipe)

```
callable function_pipe(callable ...$functions)

```

Combine all functions, piping the output from one function to the input of the other.

Each callable should only require one argument, use short closures `fn()` if needed.

```
use Improved as i;

$slugify = i\function_pipe(
    fn($str) => i\string_case_convert($str, i\STRING_LOWERCASE),
    'Improved/string_remove_accents',
    'trim',
    fn($str) => preg_replace('/\W+/', '-', $str)
);

$slugify("Bonjour du monde / Français "); // "bonjour-du-monde-francais"
```

### function\_all

[](#function_all)

```
callable function_all(callable ...$functions)

```

Call all functions sequentially. The arguments are passed to each function. The first argument is typically an accumulator.

Functions are expected to not return anything (void). If anything is returned, it's ignored.

```
use Improved as i;

$make = i\function_all(
    static function(ArrayObject $acc, array $opts): void {
        if (in_array('skip-prepare', $opts, true)) return;
        $acc[] = 'prepare';
    },
    new Compiler(), // Invokable object
    static function(ArrayObject $acc, array $opts): void {
        $acc[] = 'finish';
    }
);

$acc = new ArrayObject();
$opts = [/* ... */];

$make($acc, $opts);
```

### function\_trampoline

[](#function_trampoline)

```
callable function_trampoline(callable $callable)

```

Return a new function that decorates given function with tail recursion optimization.

In traditional recursion, the typical model is that you perform your recursive calls first, and then you take the return value of the recursive call and calculate the result. In this manner, you don't get the result of your calculation until you have returned from every recursive call.

The problem with traditional recursion is that it builds up a call stack, limiting the amount of recusion you should allow.

> Warning: Uncaught Error: Maximum function nesting level of '256' reached, aborting!

In [tail recursion](https://en.wikipedia.org/wiki/Tail_call), you perform your calculations first, and then you execute the recursive call, passing the results of your current step to the next recursive step. This results in the last statement being in the form of `return recursive_function(params, accumulator)`.

The result is calculated via the accumulator, so the return value of any given recursive step is the same as the return value of the next recursive call.

```
$sum_of_range = i\function_trampoline(function ($from, $to, $acc = 0) use (&$sum_of_range) {
    if ($from > $to) {
        return $acc;
    }

    return $sum_of_range($from + 1, $to, $acc + $from);
});

$sum_of_range(1, 10000); // 50005000;
```

Tail recursion optimization can automatically detect such a pattern and apply this as a consecutive call rather than nesting. Unfortunately this isn't implemented by PHP, so using a trampoline function is required.

**Use `function_trampoline` in case of deep recursion (10+ levels).**

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity73

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~716 days

Total

4

Last Release

622d ago

Major Versions

v0.1.2 → v1.0.02024-09-03

PHP version history (3 changes)v0.1.0PHP &gt;=7.1.0

v0.1.1PHP &gt;=7.2.0

v1.0.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3379a93d51305df325df9045e1a8b205d195e4e8c01312dff53a000ee79002eb?d=identicon)[jasny](/maintainers/jasny)

---

Top Contributors

[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (25 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/improved-function/health.svg)

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

###  Alternatives

[faonni/module-price

Rounding Price to Prettier Value for Multi-Currency Stores.

63120.9k](/packages/faonni-module-price)[php-tuf/php-tuf

PHP implementation of The Update Framework (TUF)

456.5k1](/packages/php-tuf-php-tuf)[shdev/phpflashtext

A port of the flashtext python implementation

2030.7k](/packages/shdev-phpflashtext)[magefan/module-catalog

Fixes for magento issues in catalog

2314.0k](/packages/magefan-module-catalog)[webinarium/php-dictionary

Static dictionary implementation for PHP

1019.1k](/packages/webinarium-php-dictionary)

PHPackages © 2026

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