This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.
There is no license information available for the latest version (v1.0) of this package.

v1.0 2018-12-09 07:51 UTC

This package is auto-updated.

Last update: 2021-07-10 14:03:46 UTC


Have you ever written code like this?

$array = array_filter($array);
$array = array_map(
    function($element) {
        // ... manipulations ...
        return $modifiedElement;

Know what? You could do the same in a more readable and nice way:

$chain = (new \chainy\Chain)


        function($element) {
            // ... manipulations ...
            return $modifiedElement;


$array = $chain->apply($array);

Chainy is a pipeline of functions, where every next one gets input from the previous one's output. In the example above, when $chain->apply() is called on $array, it goes sequentially through filter(), map() and sort(). As you can expect, those methods are just wrappers for the PHP's built-in functions array_filter, array_map and sort.

This is how things go with chainy:

  1. Create new Chain instance.
  2. Setup the pipeline, adding elements to the chain (in this casem filter to get rid of empty element, map to apply some modifications to every element that survived filter, and then sort the resulting array).
  3. Call Chain->apply() on the input array. The result is the filtered, modified and sorted array.
$chain = (new \chainy\Chain)

+------> filter() --+
|                   |
|    +--------------+
|    |
|    +-> map(function()...) --+
|                             |
|    +------------------------+
|    |
|    +-> sort();
| $array = $chain->apply($array);
|                          |