PHPackages                             inmanturbo/pipes - 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. inmanturbo/pipes

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

inmanturbo/pipes
================

Pipes for php with a simple api based on functional composition

v1.1.5(1y ago)8118[4 PRs](https://github.com/inmanturbo/pipes/pulls)1MITPHPPHP ^8.2CI failing

Since Aug 12Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/inmanturbo/pipes)[ Packagist](https://packagist.org/packages/inmanturbo/pipes)[ RSS](/packages/inmanturbo-pipes/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (7)Versions (17)Used By (1)

Pipes for php with a simple api based on functional composition
---------------------------------------------------------------

[](#pipes-for-php-with-a-simple-api-based-on-functional-composition)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3f9ce48c117e8db6a3f77e2a6a809ec49f3595bf62143e2a858628138ca0f93e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e6d616e747572626f2f70697065732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/inmanturbo/pipes)[![GitHub Tests Action Status](https://camo.githubusercontent.com/204a3842f9461852d4979d0cb6e1cb3360a3b01690d3cd97f44b1e562d2e9793/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f696e6d616e747572626f2f70697065732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/inmanturbo/pipes/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/36db000b7dcc4b56514b8dba9b42150c4b8f3dc1a49a55825a6fb0f88c673c82/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f696e6d616e747572626f2f70697065732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/inmanturbo/pipes/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/88871c80751f88ecd1715e0ef93fc1d83ec6f0db52cfa0e5cc5d2b7946d46168/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e6d616e747572626f2f70697065732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/inmanturbo/pipes)

Simply put, it takes the output of the last one and pipes it to the next one. Sorta like bash `cat ./file | grep -e 'waldo'`

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

[](#installation)

You can install the package via composer:

```
composer require inmanturbo/pipes
```

Or just copy or download the [`functions.php`](https://github.com/inmanturbo/pipes/blob/main/functions.php) file from this repository.

Usage
=====

[](#usage)

pipe()
------

[](#pipe)

```
require __DIR__.'/../vendor/autoload.php';

use function Inmanturbo\Pipes\pipe;

$addOne = fn ($number = 0) => $number + 1;

$five = pipe($addOne) // 1
    ->pipe(fn ($number) => $number + 1) // 2
    ->pipe($addOne) // 3
    ->pipe($addOne) // 4
    ->thenReturn(); // 4
```

It doesn't delay execution

```
$fifty = pipe(1);

    while ($fifty->result() < 50) {
        $fifty->pipe(fn ($number) => ++$number);
    }

echo $fifty->result();
// 50

```

You can also pass a class or a class string

```
use function Inmanturbo\Pipes\pipe;

class Subtract
{
    public function __invoke($number)
    {
        return $number - 1;
    }
}

$addOne = fn ($number = 0) => $number + 1;

$six = pipe($addOne, 1)
    ->pipe($addOne)
    ->pipe($addOne)
    ->pipe($addOne)
    ->then(fn ($number) => ++$number);

$five = pipe($six)
    ->pipe(Subtract::class)
    ->thenReturn();

$three = pipe(new Subtract, $five)
    ->pipe(new Subtract)
    ->thenReturn();
```

Returning results
-----------------

[](#returning-results)

results can be returned three ways:

`then()` or `thenReturn()` both a take final callback and return the result, or `result()`, which simply returns the result.

```
$addOne = fn ($number = 0) => $number + 1;

$six = pipe($addOne, 1)
    ->pipe($addOne)
    ->pipe($addOne)
    ->pipe($addOne)
    ->then(fn ($number) => ++$number);

$sixAgain = pipe($addOne, 1)
    ->pipe($addOne)
    ->pipe($addOne)
    ->pipe($addOne)
    ->thenReturn(fn ($number) => ++$number);

$five = pipe($addOne, 1)
    ->pipe($addOne)
    ->pipe($addOne)
    ->pipe($addOne)
    ->result();
```

Halting the pipeline
--------------------

[](#halting-the-pipeline)

halt()
------

[](#halt)

You can return `halt()` from a callback to halt the chain. `halt` takes an optional result as an argument which you can pass as the final `result()` of the chain. Subsequent calls to `->pipe()` will not affect the final result.

```
    use function Inmanturbo\Pipes\{pipe, halt};

    $fortyFive = pipe(1);

    $count = 1;
    while ($count < 50) {
        $fortyFive->pipe(fn ($number) => $number < 45 ? ++$number : halt($number));

        $count ++;
    }

    echo $fortyFive->result();

    // 45

    echo $fortyFive->pipe(fn ($number) => ++$number)->result();

    // 45
```

You can also call halt on the pipe itself

```
    use function Inmanturbo\Pipes\{pipe, halt};

    $fortyFive = pipe(1);

    $count = 1;
    while ($count < 50) {

        if (($number = $fortyFive->result()) >= 45) {
            $fortyFive->halt($number);
        }

        $fortyFive->pipe(fn ($number) => ++$number);

        $count ++;
    }

    echo $fortyFive->result();

    // 45

    echo $fortyFive->pipe(fn ($number) => ++$number)->result();

    // 45
```

resume()
--------

[](#resume)

You can resume the piping with resume. `pipe()->resume()` takes an optional callback and behaves the same as `pipe()->pipe()` if a callback is passed

```
use function Inmanturbo\Pipes\{pipe, halt};

$fortySix = pipe(1);

$count = 1;
while ($count < 50) {

    if (($number = $fortySix->result()) >= 45) {
        $fortySix->halt($number);
    }

    $fortySix->pipe(fn ($number) => ++$number);

    $count ++;
}

echo $fortySix->result();

// 45

echo $fortySix->resume(fn ($number) => ++$number)->result();

// 46
```

hop() and Laravel
-----------------

[](#hop-and-laravel)

This package doesn't require laravel to use pipe or `hop()`, but `hop()` (higher-order-pipe) is a higher order function intended for working with Laravel's [Pipeline](https://laravel.com/docs/11.x/helpers#pipeline) helper. This higher-order-function takes a callback which takes a single argument, and wraps the `$callback` for you in a closure which implements `function($next, $passable)`.

```
use Illuminate\Pipeline\Pipeline;

use function Inmanturbo\Pipes\hop;

class Add {
    public function add($number)
    {
        return $number +1;
    }
}
class InvokeAdd {
    public function __invoke($number)
    {
        return $number +1;
    }
}

$five = (new Pipeline)->send(1)
    ->pipe(hop(fn($number) => $number +1))
    ->pipe(hop(new InvokeAdd))
    ->pipe(hop(InvokeAdd::class))
    ->pipe(hop(fn($number) => (new Add)->add($number)))
->thenReturn();

// 5
```

You can optionally pass a single `middleware` as a second argument to `hop()`, and it will get called before the first argument, which allows you to determine if the pipeline should halt before the `$callback` ever gets executed.

```
$limitThreeMiddleware = function ($number, $next) {
    if($number >= 3) {
        Log::info('Limit hit');
        return $number;
    }

    return $next($number);
};

$five = (new Pipeline)->send(1)
    ->pipe(hop(fn($number) => $number +1, $limitThreeMiddleware))
    ->pipe(hop(new InvokeAdd, $limitThreeMiddleware))
    // Limit hit
    ->pipe(hop(InvokeAdd::class, $limitThreeMiddleware))
    ->pipe(hop(fn($number) => (new Add)->add($number), $limitThreeMiddleware))
->thenReturn();

// 3
```

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance63

Regular maintenance activity

Popularity15

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 85.1% 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 ~0 days

Total

10

Last Release

690d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0261babef618b8fb3bfcea84376ed5e71e7169586eb8de63a6550c2e7ea653a6?d=identicon)[inmanturbo](/maintainers/inmanturbo)

---

Top Contributors

[![inmanturbo](https://avatars.githubusercontent.com/u/47095624?v=4)](https://github.com/inmanturbo "inmanturbo (57 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")

---

Tags

functional-programminggleamlaravelphpphp-library

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[simple-icons/simple-icons

SVG icons for popular brands

25.3k216.2k4](/packages/simple-icons-simple-icons)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[recca0120/laravel-erd

Laravel ERD automatically generates Entity-Relationship Diagrams from your Laravel models and displays them using Vuerd.

36190.3k](/packages/recca0120-laravel-erd)[slash2nl/nova-back-button

A Laravel Nova card to display a back button.

18237.6k](/packages/slash2nl-nova-back-button)[rikudou/aws-sdk-phpstan

Allows strong typing for AWS SDK

1618.6k](/packages/rikudou-aws-sdk-phpstan)

PHPackages © 2026

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