PHPackages                             cypresslab/php-curry - 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. cypresslab/php-curry

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

cypresslab/php-curry
====================

Curried functions in PHP

0.5.0(9y ago)61135.1k↓17.6%1[1 issues](https://github.com/matteosister/php-curry/issues)2MITPHPPHP &gt;=5.3.2

Since Feb 9Pushed 7y ago2 watchersCompare

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

READMEChangelog (5)Dependencies (1)Versions (6)Used By (2)

php-curry
=========

[](#php-curry)

[![Code Coverage](https://camo.githubusercontent.com/6be926d1a8b930e4db6ac0499b326e710b8b67b4617e2e8cfc14aa398dcd2b94/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d617474656f7369737465722f7068702d63757272792f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/matteosister/php-curry/?branch=master)[![Build Status](https://camo.githubusercontent.com/1defcfd2ed005d6e3e0e2664a541c9aacc56472112097a15179b13c723ee0c66/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d617474656f7369737465722f7068702d63757272792f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/matteosister/php-curry/build-status/master)[![SensioLabsInsight](https://camo.githubusercontent.com/b1358adb794b18fbe4a4b684e87720e03f6add19c3b8031a2037ea14ed4ff679/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f34333761353164312d393832392d346532322d623337622d3737633830646433393437662f6d696e692e706e67)](https://insight.sensiolabs.com/projects/437a51d1-9829-4e22-b37b-77c80dd3947f)

An implementation for currying in PHP

Currying a function means the ability to pass a subset of arguments to a function, and receive back another function that accepts the rest of the arguments. As soon as the last one is passed it gets back the final result.

Like this:

```
use Cypress\Curry as C;

$adder = function ($a, $b, $c, $d) {
  return $a + $b + $c + $d;
};

$firstTwo = C\curry($adder, 1, 2);
echo $firstTwo(3, 4); // output 10

$firstThree = $firstTwo(3);
echo $firstThree(14); // output 20
```

Currying is a powerful (yet simple) concept, very popular in other, more purely functional languages. In haskell for example, currying is the default behavior for every function.

In PHP we still need to rely on a wrapper to simulate the behavior

How to install
--------------

[](#how-to-install)

```
composer require cypresslab/php-curry
```

In your PHP scripts (with composer autoloader in place) just import the namespace and use it!

```
use Cypress\Curry as C;

$chunker = C\curry('array_chunk', ['a', 'b']);
var_dump($chunker(1)); // output [['a'], ['b']]
var_dump($chunker(2)); // output [['a', 'b']]
```

### Right to left

[](#right-to-left)

It's possible to curry a function from left (default) or from right.

```
$divider = function ($a, $b) {
    return $a / $b;
};

$divide10By = C\curry($divider, 10);
$divideBy10 = C\curry_right($divider, 10);

echo $divide10By(10); // output 1
echo $divideBy10(100); // output 10
```

### Parameters as an array

[](#parameters-as-an-array)

You can also curry a function and pass the parameters as an array, just use the \*\_args version of the function.

```
use Cypress\Curry as C;

$divider = function ($a, $b) {
    return $a / $b;
};

$division = C\curry_args($divider, [100, 10]);
echo $division(); // output 10

$division2 = C\curry_right_args($divider, [100, 10]);
echo $division2(); // output 0.1
```

### Optional parameters

[](#optional-parameters)

Optional parameters and currying do not play very nicely together. This library excludes optional parameters by default.

```
$haystack = "haystack";
$searches = ['h', 'a', 'z'];
$strpos = C\curry('strpos', $haystack); // You can pass function as string too!
var_dump(array_map($strpos, $searches)); // output [0, 1, false]
```

But strpos has an optional $offset parameter that by default has not been considered.

If you want to take this optional $offset parameter into account you should "fix" the curry to a given length.

```
$haystack = "haystack";
$searches = ['h', 'a', 'z'];
$strpos = C\curry_fixed(3, 'strpos', $haystack);
$finders = array_map($strpos, $searches);
var_dump(array_map(function ($finder) {
    return $finder(2);
}, $finders)); // output [false, 5, false]
```

*curry\_right* has its own fixed version named *curry\_right\_fixed*

### Placeholders

[](#placeholders)

The function `__()` gets a special placeholder value used to specify "gaps" within curried functions, allowing partial application of any combination of arguments, regardless of their positions.

```
$add = function($x, $y)
{
	return $x + $y;
};
$reduce = C\curry('array_reduce');
$sum = $reduce(C\__(), $add);

echo $sum([1, 2, 3, 4], 0); // output 10
```

**Notes**:

- Placeholders should be used only for required arguments.
- When used, optional arguments must be at the end of the arguments list.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 74.4% 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 ~189 days

Total

5

Last Release

3356d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/212723?v=4)[Matteo Giachino](/maintainers/matteosister)[@matteosister](https://github.com/matteosister)

---

Top Contributors

[![matteosister](https://avatars.githubusercontent.com/u/212723?v=4)](https://github.com/matteosister "matteosister (29 commits)")[![webNeat](https://avatars.githubusercontent.com/u/2133333?v=4)](https://github.com/webNeat "webNeat (9 commits)")[![daggerhart](https://avatars.githubusercontent.com/u/1205329?v=4)](https://github.com/daggerhart "daggerhart (1 commits)")

---

Tags

functional-programmingcurry

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cypresslab-php-curry/health.svg)

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

###  Alternatives

[ihor/nspl

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

381368.5k](/packages/ihor-nspl)[react/partial

Partial function application.

115376.0k13](/packages/react-partial)[mpetrovich/dash

A functional programming library for PHP. Inspired by Underscore, Lodash, and Ramda.

10428.9k1](/packages/mpetrovich-dash)[marcosh/lamphpda

A collection of functional programming data structures

12313.5k4](/packages/marcosh-lamphpda)[daveross/functional-programming-utils

Functional Programming utilities for PHP 5.4+

225.2k](/packages/daveross-functional-programming-utils)[loophp/combinator

A curated list of combinators

1251.4k](/packages/loophp-combinator)

PHPackages © 2026

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