Skip to content

Commit 51638e7

Browse files
committed
Remove reduce() function
1 parent 9b2c528 commit 51638e7

File tree

3 files changed

+1
-327
lines changed

3 files changed

+1
-327
lines changed

README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Table of Contents
4343
* [race()](#race)
4444
* [any()](#any)
4545
* [map()](#map)
46-
* [reduce()](#reduce)
4746
4. [Examples](#examples)
4847
* [How to use Deferred](#how-to-use-deferred)
4948
* [How promise forwarding works](#how-promise-forwarding-works)
@@ -364,8 +363,7 @@ once all consumers called the `cancel()` method of the promise.
364363

365364
### Functions
366365

367-
Useful functions for creating, joining, mapping and reducing collections of
368-
promises.
366+
Useful functions for creating, joining and mapping collections of promises.
369367

370368
All functions working on promise collections (like `all()`, `race()`,
371369
etc.) support cancellation. This means, if you call `cancel()` on the returned
@@ -453,17 +451,6 @@ promises and/or values, and `$mapFunc` may return either a value or a promise.
453451
The map function receives each item as argument, where item is a fully resolved
454452
value of a promise or value in `$promisesOrValues`.
455453

456-
#### reduce()
457-
458-
```php
459-
$promise = React\Promise\reduce(array $promisesOrValues, callable $reduceFunc, $initialValue = null);
460-
```
461-
462-
Traditional reduce function, similar to `array_reduce()`, but input may contain
463-
promises and/or values, and `$reduceFunc` may return either a value or a
464-
promise, *and* `$initialValue` may be a promise or a value for the starting
465-
value.
466-
467454
Examples
468455
--------
469456

src/functions.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -211,44 +211,6 @@ function ($mapped) use ($i, &$values, &$toResolve, $resolve): void {
211211
}, $cancellationQueue);
212212
}
213213

214-
/**
215-
* Traditional reduce function, similar to `array_reduce()`, but input may contain
216-
* promises and/or values, and `$reduceFunc` may return either a value or a
217-
* promise, *and* `$initialValue` may be a promise or a value for the starting
218-
* value.
219-
*
220-
* @param array $promisesOrValues
221-
* @param callable $reduceFunc
222-
* @param mixed $initialValue
223-
* @return PromiseInterface
224-
*/
225-
function reduce(array $promisesOrValues, callable $reduceFunc, $initialValue = null): PromiseInterface
226-
{
227-
$cancellationQueue = new Internal\CancellationQueue();
228-
229-
return new Promise(function ($resolve, $reject) use ($promisesOrValues, $reduceFunc, $initialValue, $cancellationQueue): void {
230-
$total = \count($promisesOrValues);
231-
$i = 0;
232-
233-
$wrappedReduceFunc = function ($current, $val) use ($reduceFunc, $cancellationQueue, $total, &$i): PromiseInterface {
234-
$cancellationQueue->enqueue($val);
235-
236-
return $current
237-
->then(function ($c) use ($reduceFunc, $total, &$i, $val) {
238-
return resolve($val)
239-
->then(function ($value) use ($reduceFunc, $total, &$i, $c) {
240-
return $reduceFunc($c, $value, $i++, $total);
241-
});
242-
});
243-
};
244-
245-
$cancellationQueue->enqueue($initialValue);
246-
247-
\array_reduce($promisesOrValues, $wrappedReduceFunc, resolve($initialValue))
248-
->done($resolve, $reject);
249-
}, $cancellationQueue);
250-
}
251-
252214
/**
253215
* @internal
254216
*/

tests/FunctionReduceTest.php

Lines changed: 0 additions & 275 deletions
This file was deleted.

0 commit comments

Comments
 (0)