Skip to content

Commit

Permalink
Workaround for standard functions like is_int
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Mar 14, 2018
1 parent 7dedb25 commit 7b99a2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Pipeline/Principal.php
Expand Up @@ -80,6 +80,13 @@ public function map(callable $func)

public function filter(callable $func)
{
// Strings usually are internal functions, which require exact number of parameters.
if (is_string($func)) {
$func = function ($value) use ($func) {
return $func($value);
};
}

$this->pipeline = new \CallbackFilterIterator($this->pipeline, $func);

return $this;
Expand Down
8 changes: 8 additions & 0 deletions tests/Pipeline/EdgeCasesTest.php
Expand Up @@ -31,6 +31,14 @@ public function testInitialCallbackNotGenerator()
$this->assertEquals([PHP_INT_MAX], iterator_to_array($pipeline));
}

public function testStandardStringFunctions()
{
$pipeline = new Simple(new \ArrayIterator([1, 2, 'foo', 'bar']));
$pipeline->filter('is_int');

$this->assertEquals([1, 2], iterator_to_array($pipeline));
}

public function testInitialInvokeReturnsScalar()
{
$pipeline = new Simple();
Expand Down

0 comments on commit 7b99a2f

Please sign in to comment.