Skip to content

Commit

Permalink
Use a direct map() export instead of pipe()
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed May 27, 2018
1 parent 101e28f commit e40e233
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/functions.php
Expand Up @@ -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);
}
12 changes: 6 additions & 6 deletions tests/Pipeline/FunctionsTest.php
Expand Up @@ -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());
}
}

0 comments on commit e40e233

Please sign in to comment.