diff --git a/src/Standard.php b/src/Standard.php index 63c7569..b1b9faa 100644 --- a/src/Standard.php +++ b/src/Standard.php @@ -214,6 +214,16 @@ public function unpack(?callable $func = null): self }); } + /** + * Flattens inputs: arrays become lists. + * + * @return self + */ + public function flatten(): self + { + return $this->unpack(); + } + /** * Chunks the pipeline into arrays with length elements. The last chunk may contain less than length elements. * diff --git a/tests/UnpackTest.php b/tests/UnpackTest.php index ac5c7a1..458354e 100644 --- a/tests/UnpackTest.php +++ b/tests/UnpackTest.php @@ -81,4 +81,16 @@ public function testWithIterator(): void [3], ])->unpack()->toArray()); } + + /** + * @covers \Pipeline\Standard::flatten() + */ + public function testFlatten(): void + { + $this->assertSame([1, 2, 3], fromArray([ + new ArrayIterator([1]), + fromArray([2]), + [3], + ])->flatten()->toArray()); + } }