PHPackages                             j45l/functional-php - 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. j45l/functional-php

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

j45l/functional-php
===================

Functional primitives for PHP

3.0.21(2y ago)420.7k↓12.6%3MITPHPPHP ^8.2

Since Jan 15Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/jordibisbal/functional-php)[ Packagist](https://packagist.org/packages/j45l/functional-php)[ RSS](/packages/j45l-functional-php/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (11)Versions (47)Used By (3)

Functional-php
==============

[](#functional-php)

Functional primitives for PHP 8.2+, inspired by several functional libraries such as [lstrojny/functional-php](https://github.com/lstrojny/functional-php), [Typelevel Cats](https://typelevel.org/cats/), Scala, SML, etc.

This library provides a small, opinionated toolbox to write PHP in a functional style: working with collections as first-class values, composing behaviour out of small functions, and keeping side effects contained.

What you get
------------

[](#what-you-get)

### Collection filtering and selection

[](#collection-filtering-and-selection)

Pick elements out of any `iterable` without hand-rolling loops: `first` / `last` / `head` / `tail`, `butLast`, `take`, `pluck`, `select` / `reject`, `best` / `worst`, and `traverse` for matching against nested tree-like data.

### Collection transformation

[](#collection-transformation)

Reshape and combine collections: `map`, `flatMap`, `reindex`, `fold` / `foldRight`, `reduce` / `reduceRight`, `sum`, `merge` / `mergeGenerator`, `zip` / `unzip`, `concat`, `cartesianProduct`, `crossCompareSet`, `from` / `upTo`, `recurseTimes`, and conversions between iterables, arrays and generators (`toArray`, `toGenerator`, `toIterable`, `yieldIterable`, `unindex`).

### Function composition, partial application and currying

[](#function-composition-partial-application-and-currying)

Build new functions out of existing ones: `compose`, `pipe`, `partial`, `partialRight`.

### Logic and predicate helpers

[](#logic-and-predicate-helpers)

Combine and negate predicates and ask boolean questions of collections: `every`, `some`, `none`, `not`.

### Value functions

[](#value-functions)

Tiny building blocks that show up everywhere when composing: `identity`, `nop`, `trueFn`, `falseFn`, `value`, `with`.

### Object &amp; type functions

[](#object--type-functions)

Work with values whose type or shape needs checking or adjusting: `isAOr`, `isClosureOr`, `cloneWith` (clones an object and runs a closure bound to it, so even private properties can be set on the copy).

### Loop and effect functions

[](#loop-and-effect-functions)

Express imperative-shaped work without leaving the functional style: `doWhile`, `doUntil`, `doEach`, `also` (run a side effect and pass the value through), `delay`, `tryOrThrow`.

### Optimization

[](#optimization)

`tailRecursion` decorates a recursive closure with a trampoline so deep recursion does not blow the PHP stack, and `MemoizeTrait` caches results of pure methods.

### Sequences

[](#sequences)

Lazy numeric sequences as iterable objects: `LinearSequence`, `ExponentialSequence`, `FibonacciSequence`, plus the underlying `Sequence` / `SequenceIterator` to roll your own.

### Tuples

[](#tuples)

Simple immutable `Pair` and `Triplet` value objects, with factory helpers — useful as return types for functions that naturally produce two or three related values (and as the output of `crossCompareSet`).

### PHPUnit helpers

[](#phpunit-helpers)

A handful of assertion helpers in `PHPUnitFunctions.php` for testing code written in this style.

Design notes
------------

[](#design-notes)

- The library targets PHP 8.2+.
- Most functions accept any `iterable` as input and return an `array`. Some fully consume generators — beware of infinite ones.
- Only `\Closure` is accepted where a function is expected (not the looser `callable`). Wrap anything else in an arrow function, e.g. `fn(...$a) => strtolower(...$a)`.

Install
-------

[](#install)

```
composer require j45l/functional-php

```

Documentation
-------------

[](#documentation)

Per-function reference with signatures and examples: [Functions](./documentation/Functions.md).

For anything not covered there, the unit tests under `tests/` are the source of truth.

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance61

Regular maintenance activity

Popularity30

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity75

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 ~36 days

Recently: every ~280 days

Total

45

Last Release

41d ago

Major Versions

0.1.2 → 1.0.02022-03-01

1.1.0 → 2.0.02022-03-05

1.2.0 → v2.x-dev2022-04-04

1.2.5.1 → 3.0.182022-06-28

v1.x-dev → 3.0.02022-12-02

PHP version history (3 changes)0.1.0PHP ^7.1|~8

3.0.0PHP ^8.1

3.0.10PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/da578abff91c7e1eec1d6b3d3844c83196955118805bcbd974f8b8a5a114f5b3?d=identicon)[jordibisbal](/maintainers/jordibisbal)

---

Top Contributors

[![jordibisbal](https://avatars.githubusercontent.com/u/10561525?v=4)](https://github.com/jordibisbal "jordibisbal (127 commits)")

---

Tags

functional

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/j45l-functional-php/health.svg)

```
[![Health](https://phpackages.com/badges/j45l-functional-php/health.svg)](https://phpackages.com/packages/j45l-functional-php)
```

###  Alternatives

[lstrojny/functional-php

Functional primitives for PHP

2.0k7.5M51](/packages/lstrojny-functional-php)[nikic/iter

Iteration primitives using generators

1.1k6.4M55](/packages/nikic-iter)[lambdish/phunctional

λ PHP functional library

3642.1M24](/packages/lambdish-phunctional)[ihor/nspl

Non-standard PHP library (NSPL) - functional primitives toolbox and more

375369.6k](/packages/ihor-nspl)[qaribou/immutable.php

Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.

345148.0k](/packages/qaribou-immutablephp)[crell/fp

Functional utilities for PHP 8 and later

92522.8k13](/packages/crell-fp)

PHPackages © 2026

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