PHPackages                             php-fp/php-fp-combinators - 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. php-fp/php-fp-combinators

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

php-fp/php-fp-combinators
=========================

A handful of functional combinators in PHP.

11618[2 issues](https://github.com/php-fp/php-fp-combinators/issues)[4 PRs](https://github.com/php-fp/php-fp-combinators/pulls)PHP

Since Jun 13Pushed 9y agoCompare

[ Source](https://github.com/php-fp/php-fp-combinators)[ Packagist](https://packagist.org/packages/php-fp/php-fp-combinators)[ RSS](/packages/php-fp-php-fp-combinators/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Functional combinators for PHP. [![Build Status](https://camo.githubusercontent.com/6dc9f32fd9459bda0798aa8a9c616e879102539c8bfcb3093ced300438d60f85/68747470733a2f2f7472617669732d63692e6f72672f7068702d66702f7068702d66702d636f6d62696e61746f72732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/php-fp/php-fp-combinators)
==========================================================================================================================================================================================================================================================================================================================================

[](#functional-combinators-for-php-)

Intro
-----

[](#intro)

Combinators are simple functions that allow you to modify the behaviour of values and functions after they have been created. These allow greater reuse of functions and reduction of boilerplate.

API
---

[](#api)

These combinators aren't fully curried by default - mainly for optimisation reasons - but are designed so that most common use cases can be satisfied as is. Consequently, the type signatures use the comma (`,`) to represent multiple arguments.

### `compose :: (b -> c), (a -> b) -> a -> c`

[](#compose--b---c-a---b---a---c)

Instead of writing `function ($x) { return f(g(x)); }`, `compose` allows us to express this as `compose('f', 'g')` (where the parameters could be closures, invokables, or anything that can be used as a "function"). Given two functions, `f` and `g`, a function will be returned that takes a value, `x`, and returns `f(g(x))`. This operation is *associative*, so `compose` calls can nest to create longer chains of functions. A simple, two-function example is shown here:

```
