PHPackages                             selfiens/pipe - 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. selfiens/pipe

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

selfiens/pipe
=============

Minimalistic pipe

1.0(1y ago)012MITPHP

Since Dec 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/selfiens/pipe)[ Packagist](https://packagist.org/packages/selfiens/pipe)[ RSS](/packages/selfiens-pipe/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Minimalistic, PHP-First Pipe
============================

[](#minimalistic-php-first-pipe)

This package is a `pipe` implementation with the following aims:

- **Simple** signature. no "wrapper" objects.
- Based on **PHP-callable**.
- Optional and extensible **"Helper Methods"** (see below).

Code Example
------------

[](#code-example)

An example of simple string manipulation:

```
$x = pipe(
    " hello, pipe world ",
    'trim',
    'strtolower'
    'ucfirst',
);
// $x === "Hello, Pipe World"
```

The function calling order in the `pipe` matches the data processing order, unlike the plain PHP in which often requires intermediate variables or reversed function nesting.

```
// The equivalent code in plain PHP:
ucfirst( strtolower( trim( " hello, pipe world " ) ) );
```

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

[](#installation)

Use [Composer](https://getcomposer.org) to install this package. This package requires PHP 8.0 or later.

```
composer require selfiens/pipe
```

### Using Global `pipe` Function

[](#using-global-pipe-function)

The `pipe` function can be installed in the global(root) namespace.

```
// define pipe() function in the root namespace
\Selfiens\Pipe\Pipe::installGlobal();

pipe(...);
```

Alternatively, you can load the global `pipe` function via `autoload.php`. Add `"vendor/selfiens/pipe/src/pipe_global.php"` to the `autoload/files` section of your `composer.json`:

```
{
  "autoload": {
    "files": [
      "vendor/selfiens/pipe/src/pipe_global.php"
    ]
  }
}
```

**Note**: You may need to run `composer dump`

The `pipe` Function Signature
-----------------------------

[](#the-pipe-function-signature)

The first argument is the initial data, followed by callables.

```
pipe(mixed $data, ...$callables): mixed
```

Real-World Examples
-------------------

[](#real-world-examples)

Plain PHP code to extract initials:

```
// How many seconds to grasp?
$init = implode(".",
    array_map(
        fn($w) => substr($w, 0, 1),
        explode(" ", strtoupper("John Doe"))
    )
);
// $init === "J.D"
```

The pipe improves readability by easing cognitive load:

```
$init = pipe(
    "John Doe",
    strtoupper(...),
    fn($s) => explode(" ", $s),
    fn($a) => array_map(fn($w) => substr($w, 0, 1), $a),
    fn($a) => implode(".", $a),
);
// $init === "J.D"
```

This package offers optional **Helper Methods** to further enhance code readability.

```
use Selfiens\Pipe as P;

$init = pipe(
    "John Doe",
    strtoupper(...),
    P::explode(" "),
    P::map(fn($w) => substr($w, 0, 1)),
    P::implode("."),
);
```

Behavior In Depth
-----------------

[](#behavior-in-depth)

Each callable's output becomes the next callable's input:

```
$x = pipe(
    'x',
    fn($s) => $s . 'y',     // $s='x'
    fn($s) => $s . 'z',     // $s='xy'
    fn($s) => $s . '0',     // $s='xyz'
);
// $x === 'xyz0'
```

```
// no callables
pipe('my data'); // = 'my data'
```

### You can use any callable type supported by your PHP version.

[](#you-can-use-any-callable-type-supported-by-your-php-version)

```
pipe(
    'The first arg is the initial data',
    // --- Example of data transformer callables ---
    'trim',                             // global function name
    ['MyClass', 'myMethod'],            // static method (PHP 5.0)
    'MyClass::myMethod',                // static method (PHP 5.2)
    function($s) { return trim($s) },   // closure (anonymous function) (PHP 5.3)
    new MyClass(),                      // when the `__invoke()` is implemented (PHP 5.3)
    [$myObject, 'myMethod'],            // instance method (PHP 5.4)
    [MyClass::class, 'myMethod'],       // static method (PHP 7.0)
    fn($s) => trim($s),                 // arrow function (PHP 7.4)
    trim(...),                          // first-class callable (PHP 8.1)
    MyClass::myMethod(...),             // static method, first-class callable (PHP 8.1)
    $myObject->myMethod(...),           // instance method, first-class callable (PHP 8.1)
);
```

The Helper Methods
------------------

[](#the-helper-methods)

The `Pipe` class offers helper methods to simplify common array handling, such as map, filter.

```
use Selfiens\Pipe as P;

P::pipe(
    [1,2,3,4,5],
    P::map(fn($i) => $i*2),     // [2,4,6,8,10]
    P::filter(fn($i) => $i $x % $n, $data);
        }
    }
}
```

### Using `define` method

[](#using-define-method)

The `Pipe::define()` method adds custom helper methods directly to the `Pipe` class.

```
use Selfiens\Pipe as P;

P::define('sum', function(): Closure {
    return static function (array $data): int {
        return \array_sum($data);
    }
});

P::define('even', function (): Closure {
    return function (array $data): array {
        return P::pipe(
            $data,
            P::filter(fn($i) => ($i % 2) == 0),
            P::values()
        );
    };
});

P::define('odd', function (): Closure {
    return function (array $data): array {
        return P::pipe(
            $data,
            P::filter(fn($i) => ($i % 2) != 0),
            P::values()
        );
    };
});
```

More Examples
-------------

[](#more-examples)

See the examples folder for more examples.

Tests
-----

[](#tests)

```
composer test
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance40

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

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

Unknown

Total

1

Last Release

506d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/26b5b9575bb4504f1c1bf6bbf9b5c86a98f89585902220d9dbecbdc75e4a7f71?d=identicon)[selfiens](/maintainers/selfiens)

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[barracudanetworks/forkdaemon-php

A library to make setup and management of forking daemons in PHP easy.

3863.8k2](/packages/barracudanetworks-forkdaemon-php)

PHPackages © 2026

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