Skip to content

Commit

Permalink
take() can safely pass through all iterables, not just traversables
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Oct 19, 2018
1 parent 9700386 commit efcbbec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/functions.php
Expand Up @@ -30,12 +30,12 @@ function map(callable $func = null): Standard
return $pipeline->map($func);
}

function take(\Traversable $input = null): Standard
function take(iterable $input = null): Standard
{
return new Standard($input);
}

function fromArray(array $input): Standard
{
return take(new \ArrayIterator($input));
return new Standard($input);
}
8 changes: 8 additions & 0 deletions tests/FunctionsTest.php
Expand Up @@ -65,6 +65,14 @@ public function testTakeFunction()
$this->assertSame(6, $pipeline->reduce());
}

/**
* @covers \Pipeline\take
*/
public function testTakeArray()
{
$this->assertSame([1, 2, 3, 4, 5], take([1, 2, 3, 4, 5])->toArray());
}

/**
* @covers \Pipeline\fromArray
*/
Expand Down

0 comments on commit efcbbec

Please sign in to comment.