PHPackages                             react/partial - 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. react/partial

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

react/partial
=============

Partial function application.

v3.0.0(8y ago)115376.0k↓11.2%613MITPHPPHP &gt;=5.6

Since Aug 30Pushed 8y ago14 watchersCompare

[ Source](https://github.com/friends-of-reactphp/partial)[ Packagist](https://packagist.org/packages/react/partial)[ RSS](/packages/react-partial/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (13)

React/Partial
=============

[](#reactpartial)

Partial function application.

[![Build Status](https://camo.githubusercontent.com/5684940f0f73934c43f55558785a3cc38a108342c48e35a2d9f63365f6531cd6/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f72656163747068702f7061727469616c2e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/reactphp/partial) [![Code Climate](https://camo.githubusercontent.com/634a2774d19c816b515f1b1a0116327b6e02225c45e2cac9a588efabc6792a55/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f72656163747068702f7061727469616c2f6261646765732f6770612e737667)](https://codeclimate.com/github/reactphp/partial)

Install
-------

[](#install)

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

```
{
    "require": {
        "react/partial": "~2.0"
    }
}
```

Concept
-------

[](#concept)

> Partial application (or partial function application) refers to the process of fixing a number of arguments to a function, producing another function of smaller arity. Given a function `f:(X x Y x Z) -> N`, we might fix (or 'bind') the first argument, producing a function of type `f:(Y x Z) -> N`. Evaluation of this function might be represented as `f partial(2, 3)`. Note that the result of partial function application in this case is a function that takes two arguments.

Basically, what this allows you to do is pre-fill arguments of a function, which is particularly useful if you don't have control over the function caller.

Let's say you have an async operation which takes a callback. How about a file download. The callback is called with a single argument: The contents of the file. Let's also say that you have a function that you want to be called once that file download completes. This function however needs to know an additional piece of information: the filename.

```
public function handleDownload($filename)
{
    $this->downloadFile($filename, ...);
}

public function downloadFile($filename, $callback)
{
    $contents = get the darn file asynchronously...
    $callback($contents);
}

public function processDownloadResult($filename, $contents)
{
    echo "The file $filename contained a shitload of stuff:\n";
    echo $contents;
}
```

The conventional approach to this problem is to wrap everything in a closure like so:

```
public function handleDownload($filename)
{
    $this->downloadFile($filename, function ($contents) use ($filename) {
        $this->processDownloadResult($filename, $contents);
    });
}
```

This is not too bad, especially with PHP 5.4, but with 5.3 you need to do the annoying `$that = $this` dance, and in general it's a lot of verbose boilerplate that you don't really want to litter your code with.

This is where partial application can help. Since we want to pre-fill an argument to the function that will be called, we just call `bind`, which will insert it to the left of the arguments list. The return value of `bind` is a new function which takes one `$content` argument.

```
use function React\Partial\bind;

public function handleDownload($filename)
{
    $this->downloadFile($filename, bind([$this, 'processDownloadResult'], $filename));
}
```

Partialing is dependency injection for functions! How awesome is that?

Examples
--------

[](#examples)

### bind

[](#bind)

```
use function React\Partial\bind;

$add = function ($a, $b) {
    return $a + $b;
};

$addOne = bind($add, 1);

echo sprintf("%d\n", $addOne(5));
// outputs 6
```

### bind\_right

[](#bind_right)

```
use function React\Partial\bind_right;

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

$divMore = bind_right($div, 20, 10);

echo sprintf("%F\n", $divMore(100)); // 100 / 20 / 10
// outputs 0.5
```

### placeholder

[](#placeholder)

It is possible to use the `…` function (there is an alias called `placeholder`) to skip some arguments when partially applying.

This allows you to pre-define arguments on the right, and have the left ones bound at call time.

This example skips the first argument and sets the second and third arguments to `0` and `1` respectively. The result is a function that returns the first character of a string.

**Note:** Usually your IDE should help but accessing the "…"-character (HORIZONTAL ELLIPSIS, U+2026) differs on various platforms.

- Windows: `ALT + 0133`
- Mac: `ALT + ;` or `ALT + .`
- Linux: `AltGr + .`

```
use function React\Partial\bind;
use function React\Partial\…;

$firstChar = bind('substr', …(), 0, 1);
$mapped = array_map($firstChar, array('foo', 'bar', 'baz'));

var_dump($mapped);
// outputs ['f', 'b', 'b']
```

Tests
-----

[](#tests)

To run the test suite, you need PHPUnit.

```
$ phpunit

```

License
-------

[](#license)

MIT, see LICENSE.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community37

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 50.6% 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 ~497 days

Total

4

Last Release

3151d ago

Major Versions

v2.0.2 → v3.0.02017-10-01

PHP version history (2 changes)v2.0.0PHP &gt;=5.3.2

v3.0.0PHP &gt;=5.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/147145?v=4)[Cees-Jan Kiewiet](/maintainers/WyriHaximus)[@WyriHaximus](https://github.com/WyriHaximus)

![](https://avatars.githubusercontent.com/u/776829?v=4)[Christian Lück](/maintainers/clue)[@clue](https://github.com/clue)

![](https://www.gravatar.com/avatar/5de14776bbddf901c6e24d35829fe66fe997c303d53aca83cc7d1a90bb0b7110?d=identicon)[jsor](/maintainers/jsor)

![](https://www.gravatar.com/avatar/3afcc18d00fff840775bbf9570b3e9cd3997ca4820b9bfb14caf6da3ae580370?d=identicon)[igorw](/maintainers/igorw)

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

---

Top Contributors

[![igorw](https://avatars.githubusercontent.com/u/88061?v=4)](https://github.com/igorw "igorw (39 commits)")[![lstrojny](https://avatars.githubusercontent.com/u/79707?v=4)](https://github.com/lstrojny "lstrojny (14 commits)")[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (7 commits)")[![cboden](https://avatars.githubusercontent.com/u/617694?v=4)](https://github.com/cboden "cboden (3 commits)")[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (3 commits)")[![edorian](https://avatars.githubusercontent.com/u/247397?v=4)](https://github.com/edorian "edorian (2 commits)")[![indeyets](https://avatars.githubusercontent.com/u/13445?v=4)](https://github.com/indeyets "indeyets (1 commits)")[![jsor](https://avatars.githubusercontent.com/u/55574?v=4)](https://github.com/jsor "jsor (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![umpirsky](https://avatars.githubusercontent.com/u/208957?v=4)](https://github.com/umpirsky "umpirsky (1 commits)")[![whatthejeff](https://avatars.githubusercontent.com/u/306525?v=4)](https://github.com/whatthejeff "whatthejeff (1 commits)")[![clue](https://avatars.githubusercontent.com/u/776829?v=4)](https://github.com/clue "clue (1 commits)")[![adityamenon-exp](https://avatars.githubusercontent.com/u/18206894?v=4)](https://github.com/adityamenon-exp "adityamenon-exp (1 commits)")[![e3betht](https://avatars.githubusercontent.com/u/1811561?v=4)](https://github.com/e3betht "e3betht (1 commits)")[![ephrin](https://avatars.githubusercontent.com/u/537797?v=4)](https://github.com/ephrin "ephrin (1 commits)")

---

Tags

functional-programmingpartial

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/react-partial/health.svg)

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

###  Alternatives

[ihor/nspl

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

381368.5k](/packages/ihor-nspl)[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)[loophp/combinator

A curated list of combinators

1251.4k](/packages/loophp-combinator)[chemem/bingo-functional

A simple functional programming library.

716.9k3](/packages/chemem-bingo-functional)[daveross/functional-programming-utils

Functional Programming utilities for PHP 5.4+

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

PHPackages © 2026

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