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

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

martinezdelariva/functional
===========================

Syntax enhancement operators of functional programming

v0.4-alpha(9y ago)7172MITPHPPHP &gt;=7.1

Since Apr 23Pushed 9y ago3 watchersCompare

[ Source](https://github.com/martinezdelariva/functional)[ Packagist](https://packagist.org/packages/martinezdelariva/functional)[ RSS](/packages/martinezdelariva-functional/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Functional
==========

[](#functional)

[![Build Status](https://camo.githubusercontent.com/f02a311732fcdb0baea2ef22554d264f9e9c8f02b952946914e858c93a738356/68747470733a2f2f7472617669732d63692e6f72672f6d617274696e657a64656c61726976612f66756e6374696f6e616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/martinezdelariva/functional)

Syntax enhancement operators of functional programming:

- Curry
- Pipe
- Pattern Match
- Fold

At the moment there are plans to include [curry](https://wiki.php.net/rfc/currying) and [pipe](https://wiki.php.net/rfc/pipe-operator) as PHP functions. Meanwhile you can use this library for fun!

Notes:

- `curry` doesn't know if a function with optional params won't be provided. So, `curry` only runs the function curried when all params are given.
- *currying* vs *partial function application* [Wikipedia](https://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application)

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

[](#installation)

Install it using [Composer](https://getcomposer.org/)

```
composer require martinezdelariva/functional

```

Usage
-----

[](#usage)

Importing as a single function:

```
   namespace Foo;

   use function Martinezdelariva\Functional\pipe;

   class Bar
   {
        public function baz()
        {
            pipe(
                'trim',
                'ucwords'
            )(' string ');
        }
   }
```

Importing namespace:

```
   namespace Foo;

   use Martinezdelariva\Functional as F;

   class Bar
   {
        public function baz()
        {
            F\pipe(
                'trim',
                'ucwords'
            )(' string ');
        }
   }
```

Functions
---------

[](#functions)

#### curry

[](#curry)

```
function sum(int $one, int $two, int $three) : int {
    return $one + $two + $three;
};

// curry firsts params
$sum3 = curry('sum', 1, 2);
$sum3(3); // output: 6
$sum3(5); // output: 8

// curry whole function
$sum  = curry('sum');
$sum1 = $sum(1);
$sum1(2, 3); // output: 6

// curry with all params given
curry(sum::class, 1, 2, 3); // output: 6
```

#### curry\_left

[](#curry_left)

`curry_left` is an alias of `curry`.

#### curry\_right

[](#curry_right)

```
function minus(int $one, int $two) : int {
    return $one - $two;
};

$minus1 = curry_right('minus');
echo $minus1(1)(4); // output: 3
```

#### match

[](#match)

```
$patterns = [
    'a'              => "It's an 'a'",
    'foo'            => function ($input, $other) {
                            return "$input::$other";
                        },
    'is_int'         => function ($input) {
                            return $input + 1;
                        },
    \stdClass::class => "It's an 'stdClass'",
    _                => "Default"
];

// provinding params
match($patterns, 'a');          // output: "It's an 'a'"

// provinding one by one param due `match` is curried
$match = match($patterns);
$match(5);                      // output: 6
$match(new \stdClass());        // output: "It's an 'stdClass'"
$match('unknown');              // output: "Default"

// provinding param to callables with more params
$match('foo')('bar');           // output: foo::bar
```

#### Pipe

[](#pipe)

```
$format = pipe(
    'trim',
    'ucwords',
    function (string $names) : string {
        return implode(', ', explode(' ', $names));
    }
);

$format('  john mary andre'); // output: John, Mary, Andre
```

#### Fold

[](#fold)

```
// example: using fold to sum integers
$sum = fold(function($item, $carry) {
   return $item + $carry;
}, 0);
$sum([1, 2, 3, 4]); // output 10

// example: dynamically changing the fold function
$match = match([
   'is_string'  =>  function($item, $carry) {
                        return $carry.$item;
                    },
   'is_int'     =>  function($item, $carry) {
                        return "$carry{X}";
                    },
]);

fold($match, '', ['a', 'b', 'c', 2, 'd', 'e']);  // output "abc{X}de"
```

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

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.

###  Release Activity

Cadence

Every ~18 days

Total

4

Last Release

3299d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1567749?v=4)[José Luis Martínez de la Riva Manzano](/maintainers/martinezdelariva)[@martinezdelariva](https://github.com/martinezdelariva)

---

Top Contributors

[![martinezdelariva](https://avatars.githubusercontent.com/u/1567749?v=4)](https://github.com/martinezdelariva "martinezdelariva (8 commits)")

---

Tags

pipefunctionalcurrypattern match

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[react/stream

Event-driven readable and writable streams for non-blocking I/O in ReactPHP

691139.1M205](/packages/react-stream)[lstrojny/functional-php

Functional primitives for PHP

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

Iteration primitives using generators

1.1k6.2M51](/packages/nikic-iter)[ihor/nspl

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

375369.1k](/packages/ihor-nspl)[lambdish/phunctional

λ PHP functional library

3632.1M24](/packages/lambdish-phunctional)[sebastiaanluca/php-pipe-operator

Method chaining (or fluent expressions) for any value using any method.

287468.9k2](/packages/sebastiaanluca-php-pipe-operator)

PHPackages © 2026

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