Skip to content

Instantly share code, notes, and snippets.

@irsyadrdp
Last active January 3, 2019 03:40
Show Gist options
  • Save irsyadrdp/25642674fcf556189fb1f188655004f0 to your computer and use it in GitHub Desktop.
Save irsyadrdp/25642674fcf556189fb1f188655004f0 to your computer and use it in GitHub Desktop.

Revisions

  1. irsyadrdp revised this gist Jan 3, 2019. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions pipeline.php
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,7 @@ public static function make_pipeline(...$funcs)
    }
    }

    $fun = Pipeline::make_pipeline(function($x) { return $x * 3; }, function($x) { return $x + 1; },
    function($x) { return $x / 2; });
    $fun = Pipeline::make_pipeline(function($x) { return $x * 3; }, function($x) { return $x + 1; }, function($x) { return $x / 2; });

    // Sample test case
    echo $fun(3); # should print 5
  2. irsyadrdp revised this gist Jan 3, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pipeline.php
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ public static function make_pipeline(...$funcs)
    {
    return function($arg) use ($funcs)
    {
    // Call each function in loop
    // Call each function in loop
    foreach($funcs as $func) (!isset($param)) ? $param = $func($arg) : $param = $func($param);
    return $param;
    };
  3. irsyadrdp created this gist Jan 3, 2019.
    19 changes: 19 additions & 0 deletions pipeline.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?php
    class Pipeline
    {
    public static function make_pipeline(...$funcs)
    {
    return function($arg) use ($funcs)
    {
    // Call each function in loop
    foreach($funcs as $func) (!isset($param)) ? $param = $func($arg) : $param = $func($param);
    return $param;
    };
    }
    }

    $fun = Pipeline::make_pipeline(function($x) { return $x * 3; }, function($x) { return $x + 1; },
    function($x) { return $x / 2; });

    // Sample test case
    echo $fun(3); # should print 5