From 7422d6194907701b99592b3e7eb70a9ad365dcbf Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Wed, 13 Dec 2017 23:57:44 +0100 Subject: [PATCH] =?UTF-8?q?Rename=20parallelMap=20=E2=86=92=20map,=20paral?= =?UTF-8?q?lelFilter=20=E2=86=92=20filter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/1-simple-function.php | 4 ++-- examples/2-echo.php | 4 ++-- examples/3-return-value.php | 4 ++-- examples/4-closure.php | 4 ++-- src/functions.php | 4 ++-- test/{ParallelFilterTest.php => FilterTest.php} | 16 ++++++++-------- test/{ParallelMapTest.php => MapTest.php} | 10 +++++----- 7 files changed, 23 insertions(+), 23 deletions(-) rename test/{ParallelFilterTest.php => FilterTest.php} (79%) rename test/{ParallelMapTest.php => MapTest.php} (80%) diff --git a/examples/1-simple-function.php b/examples/1-simple-function.php index 419541d..ecfdec5 100644 --- a/examples/1-simple-function.php +++ b/examples/1-simple-function.php @@ -2,7 +2,7 @@ require __DIR__ . '/../vendor/autoload.php'; -use function Amp\ParallelFunctions\parallelMap; +use function Amp\ParallelFunctions\map; use function Amp\Promise\wait; $start = \microtime(true); @@ -11,6 +11,6 @@ $start = \microtime(true); // // All communication is non-blocking and can be used in an event loop. Amp\Promise\wait() can be used to use the library // in a traditional synchronous environment. -wait(parallelMap([1, 2, 3], 'sleep')); +wait(map([1, 2, 3], 'sleep')); print 'Took ' . (\microtime(true) - $start) . ' milliseconds.' . \PHP_EOL; diff --git a/examples/2-echo.php b/examples/2-echo.php index ece2ac2..30076d9 100644 --- a/examples/2-echo.php +++ b/examples/2-echo.php @@ -2,9 +2,9 @@ require __DIR__ . '/../vendor/autoload.php'; -use function Amp\ParallelFunctions\parallelMap; +use function Amp\ParallelFunctions\map; use function Amp\Promise\wait; // All output in the parallel environment is redirected to STDERR of the parent process automatically. // You might notice that the output order varies here when running it multiple times. -wait(parallelMap([1, 2, 3], 'var_dump')); +wait(map([1, 2, 3], 'var_dump')); diff --git a/examples/3-return-value.php b/examples/3-return-value.php index 5844578..ba79557 100644 --- a/examples/3-return-value.php +++ b/examples/3-return-value.php @@ -2,8 +2,8 @@ require __DIR__ . '/../vendor/autoload.php'; -use function Amp\ParallelFunctions\parallelMap; +use function Amp\ParallelFunctions\map; use function Amp\Promise\wait; // We have seen that the order can vary in the previous example, values returned have a deterministic order. -\var_dump(wait(parallelMap([1, 2, 3], 'abs'))); +\var_dump(wait(map([1, 2, 3], 'abs'))); diff --git a/examples/4-closure.php b/examples/4-closure.php index 2038872..c97fbbd 100644 --- a/examples/4-closure.php +++ b/examples/4-closure.php @@ -2,12 +2,12 @@ require __DIR__ . '/../vendor/autoload.php'; -use function Amp\ParallelFunctions\parallelMap; +use function Amp\ParallelFunctions\map; use function Amp\Promise\wait; // Parallel function execution is nice, but it's even better being able to use closures instead of having to write a // function that has to be autoloadable. -\var_dump(wait(parallelMap([1, 2, 3], function ($time) { +\var_dump(wait(map([1, 2, 3], function ($time) { \sleep($time); // a blocking function call, might also do blocking I/O here return $time * $time; diff --git a/src/functions.php b/src/functions.php index 7e02507..7facb42 100644 --- a/src/functions.php +++ b/src/functions.php @@ -54,7 +54,7 @@ function parallel(callable $callable): callable { * @return Promise Resolves to the result once the operation finished. * @throws \Error */ -function parallelMap(array $array, callable $callable): Promise { +function map(array $array, callable $callable): Promise { return call(function () use ($array, $callable) { // Amp\Promise\any() guarantees that all operations finished prior to resolving. Amp\Promise\all() doesn't. // Additionally, we return all errors as a MultiReasonException instead of throwing on the first error. @@ -77,7 +77,7 @@ function parallelMap(array $array, callable $callable): Promise { * * @return Promise */ -function parallelFilter(array $array, callable $callable = null, int $flag = 0): Promise { +function filter(array $array, callable $callable = null, int $flag = 0): Promise { return call(function () use ($array, $callable, $flag) { if ($callable === null) { if ($flag === \ARRAY_FILTER_USE_BOTH || $flag === \ARRAY_FILTER_USE_KEY) { diff --git a/test/ParallelFilterTest.php b/test/FilterTest.php similarity index 79% rename from test/ParallelFilterTest.php rename to test/FilterTest.php index aaed3e1..581640d 100644 --- a/test/ParallelFilterTest.php +++ b/test/FilterTest.php @@ -4,14 +4,14 @@ namespace Amp\ParallelFunctions\Test; use Amp\MultiReasonException; use Amp\PHPUnit\TestCase; -use function Amp\ParallelFunctions\parallelFilter; +use function Amp\ParallelFunctions\filter; use function Amp\Promise\wait; -class ParallelFilterTest extends TestCase { +class FilterTest extends TestCase { public function testWithoutCallback() { $input = [1, 0, 3, false, true, null]; - $this->assertSame(\array_filter($input), wait(parallelFilter($input))); + $this->assertSame(\array_filter($input), wait(filter($input))); } public function testWithCallback() { @@ -20,7 +20,7 @@ class ParallelFilterTest extends TestCase { return $value === false; }; - $this->assertSame(\array_filter($input, $callback), wait(parallelFilter($input, $callback))); + $this->assertSame(\array_filter($input, $callback), wait(filter($input, $callback))); } public function testWithCallbackAndFlagKey() { @@ -29,7 +29,7 @@ class ParallelFilterTest extends TestCase { return $key === 2; }; - $this->assertSame(\array_filter($input, $callback, \ARRAY_FILTER_USE_KEY), wait(parallelFilter($input, $callback, \ARRAY_FILTER_USE_KEY))); + $this->assertSame(\array_filter($input, $callback, \ARRAY_FILTER_USE_KEY), wait(filter($input, $callback, \ARRAY_FILTER_USE_KEY))); } public function testWithCallbackAndFlagBoth() { @@ -38,13 +38,13 @@ class ParallelFilterTest extends TestCase { return $key === 2 || $value === true; }; - $this->assertSame(\array_filter($input, $callback, \ARRAY_FILTER_USE_BOTH), wait(parallelFilter($input, $callback, \ARRAY_FILTER_USE_BOTH))); + $this->assertSame(\array_filter($input, $callback, \ARRAY_FILTER_USE_BOTH), wait(filter($input, $callback, \ARRAY_FILTER_USE_BOTH))); } public function testException() { $this->expectException(MultiReasonException::class); - wait(parallelFilter([1, 2, 3], function () { + wait(filter([1, 2, 3], function () { throw new \Exception; })); } @@ -57,7 +57,7 @@ class ParallelFilterTest extends TestCase { ]; try { - wait(parallelFilter($files, function ($args) { + wait(filter($files, function ($args) { list($id, $filename) = $args; if ($id === 0) { diff --git a/test/ParallelMapTest.php b/test/MapTest.php similarity index 80% rename from test/ParallelMapTest.php rename to test/MapTest.php index 9953599..be2f301 100644 --- a/test/ParallelMapTest.php +++ b/test/MapTest.php @@ -4,12 +4,12 @@ namespace Amp\ParallelFunctions\Test; use Amp\MultiReasonException; use Amp\PHPUnit\TestCase; -use function Amp\ParallelFunctions\parallelMap; +use function Amp\ParallelFunctions\map; use function Amp\Promise\wait; -class ParallelMapTest extends TestCase { +class MapTest extends TestCase { public function testValidInput() { - $this->assertSame([3, 4, 5], wait(parallelMap([1, 2, 3], function ($input) { + $this->assertSame([3, 4, 5], wait(map([1, 2, 3], function ($input) { return $input + 2; }))); } @@ -17,7 +17,7 @@ class ParallelMapTest extends TestCase { public function testException() { $this->expectException(MultiReasonException::class); - wait(parallelMap([1, 2, 3], function () { + wait(map([1, 2, 3], function () { throw new \Exception; })); } @@ -30,7 +30,7 @@ class ParallelMapTest extends TestCase { ]; try { - wait(parallelMap($files, function ($args) { + wait(map($files, function ($args) { list($id, $filename) = $args; if ($id === 0) {