From efcbbec8b9e3b1c5f8128f159b6c21f4ec64d187 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Fri, 19 Oct 2018 18:59:10 +0900 Subject: [PATCH] take() can safely pass through all iterables, not just traversables --- src/functions.php | 4 ++-- tests/FunctionsTest.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/functions.php b/src/functions.php index 01259ad..1a3fcbb 100644 --- a/src/functions.php +++ b/src/functions.php @@ -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); } diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 5edd86b..d8c209f 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -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 */