Skip to content

Commit

Permalink
Principal::map() - If we know the callback is one of us, we can use a…
Browse files Browse the repository at this point in the history
… shortcut
  • Loading branch information
sanmai committed Mar 25, 2018
1 parent a8e3690 commit ed1b434
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Pipeline/Principal.php
Expand Up @@ -43,6 +43,13 @@ public function __construct(\Traversable $input = null)

public function map(callable $func)
{
// If we know the callback is one of us, we can use a shortcut
if ($func instanceof self) {
$this->pipeline = call_user_func($func);

return $this;
}

if (!$this->pipeline) {
$this->pipeline = call_user_func($func);

Expand Down
3 changes: 1 addition & 2 deletions tests/Pipeline/SimpleTest.php
Expand Up @@ -181,8 +181,7 @@ public function testPipelineInPipeline()
});

$pipeline2 = new Simple();
$pipeline2->map($pipeline1);
$pipeline2->filter(function ($i) {
$pipeline2->map($pipeline1)->filter(function ($i) {
return $i % 2 != 0;
});

Expand Down

0 comments on commit ed1b434

Please sign in to comment.