PHP code example of sassnowski / pipeline

1. Go to this page and download the library: Download sassnowski/pipeline library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sassnowski / pipeline example snippets


fn5(fn4(fn3(fn2(fn1($initialValue)))));

Pipeline::pipe($initialValue)
    ->through($fn1)
    ->through($fn2)
    ->through($fn3)
    ->through($fn4)
    ->through($fn5)
    ->run();

use Sassnowski\Pipeline\Pipeline;

Pipeline::pipe(10)
    ->through(function ($i) { return $i + 10; })
    ->run();
// 11

$pipeline1 = Pipeline::build()->through(function ($i) { return $i + 1 });

// Use the existing pipeline and simply add on additional steps.
$pipeline2 = $pipeline1->through(function ($i) { return $i * 10; });

// The initial pipeline remains unchanged.
$pipeline1->run(10); // 11

$pipeline2->run(10); // 110

class Add10
{
    function __invoke($i)
    {
        return $i + 10;
    }
}

// Somewhere else
Pipeline::pipe(10)
    ->through(new Add10)
    ->run();
// 20

Pipeline::pipe(10)->through(10); // InvalidArgumentException

Pipeline::build()->through(function ($i) { return $i + 10; })->run() // RuntimeException

Pipeline::pipe(10)
    ->firstThrough($fn1)
    ->andThen($fn2)
    ->andThen($fn3)
    ->run();