PHPackages                             phamda/phamda - 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. phamda/phamda

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

phamda/phamda
=============

Auto-curried function library

0.7.0(9y ago)1922.8k↓20%1[1 PRs](https://github.com/mpajunen/phamda/pulls)MITPHPPHP &gt;=7.0

Since Mar 22Pushed 2y ago6 watchersCompare

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

READMEChangelogDependencies (3)Versions (9)Used By (0)

Phamda
======

[](#phamda)

Phamda is an auto-curried function library for PHP, heavily inspired by the Javascript library [Ramda](http://ramdajs.com/). PHP 7.0+ or HHVM is required.

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

[](#installation)

Using composer: `composer require phamda/phamda`

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

[](#documentation)

Documentation [is available on Read the Docs](https://phamda.readthedocs.io).

Examples
--------

[](#examples)

These examples highlight the major features of Phamda. Basic usage examples can also be found on the [function list](https://phamda.readthedocs.io/en/latest/functions.html).

### Currying

[](#currying)

Nearly all of the functions use automatic partial application or **currying**. For example you can call the `filter` function with only the predicate callback and get a new function:

```
use Phamda\Phamda as P;

$isPositive   = function ($x) { return $x > 0; };
$list         = [5, 7, -3, 19, 0, 2];
$getPositives = P::filter($isPositive);

$getPositives($list) === [5, 7, 3 => 19, 5 => 2];
```

The final result is the same as using two arguments directly. Of course this new function could now be used to filter other lists as well.

It's also possible to create new curried functions, including from native PHP functions. The `curry` function takes a function and initial parameters and returns a new function:

```
$replaceBad = P::curry('str_replace', 'bad', 'good');

$replaceBad('bad day') === 'good day';
$replaceBad('not bad') === 'not good';
```

### Composition

[](#composition)

Phamda functions are **composable**. The basic functions can be used to create new, more complex functions. There are also several functions to help with function composition. For example the `compose` function takes multiple argument functions and returns a new function. Calling this new function applies the argument functions in succession:

```
$double           = function ($x) { return $x * 2; };
$addFive          = function ($x) { return $x + 5; };
$addFiveAndDouble = P::compose($double, $addFive);

$addFiveAndDouble(16) === 42;

// Equivalent to calling $double($addFive(16));
```

Often the `pipe` function is a more natural way to compose functions. It is similar to `compose`, but the argument functions are applied in reverse order:

```
$doubleAndAddFive = P::pipe($double, $addFive);

$doubleAndAddFive(16) === 37;
```

### Parameter order

[](#parameter-order)

When using functional techniques it's usually most convenient if data is the last parameter. Often native PHP and library functions do not follow for this pattern. Phamda includes some tools to make it easier to use these functions functionally. The simplest is `flip`, it switches the order of the first two parameters:

```
$pow   = function ($a, $b) { return $a ** $b; };
$powOf = P::flip($pow);

$pow(2, 8) === 256;
$powOf(2, 8) === 64;
```

`twist` is somewhat more complicated and will return a new function where the original first parameter is now last:

```
$redact = P::twist('substr_replace')('REDACTED', 5);

$redact('foobarbaz') === 'foobaREDACTED';
```

Using `twist` may not work well with variadic functions. This is where `twistN` can be useful. It requires an additional parameter to set the location of the replaced parameter.

All of these functions return curried functions.

### Pipelines

[](#pipelines)

Combining these techniques allows the building of function pipelines. In this example they are applied to processing a list of badly formatted product data:

```
$products = [
    ['category' => 'QDT', 'weight' => 65.8, 'price' => 293.5, 'number' => 15708],
    ['number' => 59391, 'price' => 366.64, 'category' => 'NVG', 'weight' => 15.5],
    ['category' => 'AWK', 'number' => 89634, 'price' => 341.92, 'weight' => 35],
    ['price' => 271.8, 'weight' => 5.3, 'number' => 38718, 'category' => 'ETW'],
    ['price' => 523.63, 'weight' => 67.9, 'number' => 75905, 'category' => 'YVM'],
    ['price' => 650.31, 'weight' => 3.9, 'category' => 'XPA', 'number' => 46289],
    ['category' => 'WGX', 'weight' => 75.5, 'number' => 26213, 'price' => 471.44],
    ['category' => 'KCF', 'price' => 581.85, 'weight' => 31.9, 'number' => 48160],
];

$formatPrice = P::flip('number_format')(2);
$process     = P::pipe(
    P::filter( // Only include products that...
        P::pipe(
            P::prop('weight'), // ... weigh...
            P::gt(50.0) // ... less than 50.0.
        )
    ),
    P::map( // For each product...
        P::pipe(
            // ... drop the weight field and fix field order:
            P::pick(['number', 'category', 'price']),
            // ... and format the price:
            P::evolve(['price' => $formatPrice])
        )
    ),
    P::sortBy( // Sort the products by...
        P::prop('number') // ... comparing product numbers.
    )
);

$process($products) === [
    ['number' => 38718, 'category' => 'ETW', 'price' => '271.80'],
    ['number' => 46289, 'category' => 'XPA', 'price' => '650.31'],
    ['number' => 48160, 'category' => 'KCF', 'price' => '581.85'],
    ['number' => 59391, 'category' => 'NVG', 'price' => '366.64'],
    ['number' => 89634, 'category' => 'AWK', 'price' => '341.92'],
];
```

License
-------

[](#license)

MIT license, see LICENSE file.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

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

Total

8

Last Release

3340d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.6.0

0.7.0PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7025066?v=4)[Mikael Kujanpää](/maintainers/mpajunen)[@mpajunen](https://github.com/mpajunen)

---

Top Contributors

[![mpajunen](https://avatars.githubusercontent.com/u/7025066?v=4)](https://github.com/mpajunen "mpajunen (245 commits)")

---

Tags

curried-functionscurryfunction-compositionphpfunctionalcurrycompose

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[lstrojny/functional-php

Functional primitives for PHP

2.0k7.3M48](/packages/lstrojny-functional-php)[nikic/iter

Iteration primitives using generators

1.1k5.9M38](/packages/nikic-iter)[ihor/nspl

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

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

λ PHP functional library

3612.0M23](/packages/lambdish-phunctional)[qaribou/immutable.php

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

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

Functional utilities for PHP 8 and later

91429.8k11](/packages/crell-fp)

PHPackages © 2026

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