diff --git a/src/functions.php b/src/functions.php index beed86b..0d4a2f4 100644 --- a/src/functions.php +++ b/src/functions.php @@ -19,9 +19,13 @@ namespace Pipeline; -if (!function_exists('pipe')) { - function pipe(...$args): Standard - { - return new Standard(...$args); +function map(callable $func = null): Standard +{ + $pipeline = new Standard(); + + if (!$func) { + return $pipeline; } + + return $pipeline->map($func); } diff --git a/tests/Pipeline/FunctionsTest.php b/tests/Pipeline/FunctionsTest.php index b929453..62d0445 100644 --- a/tests/Pipeline/FunctionsTest.php +++ b/tests/Pipeline/FunctionsTest.php @@ -21,26 +21,26 @@ use PHPUnit\Framework\TestCase; use Pipeline\Standard; -use function Pipeline\pipe; +use function Pipeline\map; /** - * @covers \Pipeline\pipe + * @covers \Pipeline\map */ class FunctionsTest extends TestCase { public function testPipeFunction() { - $pipeline = pipe(); + $pipeline = map(); $this->assertInstanceOf(Standard::class, $pipeline); + $this->assertSame([], iterator_to_array($pipeline)); - $pipeline->map(function () { + $pipeline = map(function () { yield 1; yield 2; }); - $this->assertSame(3, $pipeline->reduce()); + $this->assertInstanceOf(Standard::class, $pipeline); - $pipeline = pipe(new \ArrayIterator([1, 2])); $this->assertSame(3, $pipeline->reduce()); } }