Skip to main content

Function: reduceConcur()

Returns the result of reducing the concurIterable using asyncReducer.

Informally, an initial accumulator is created using RawAsyncReducerWithoutFinish.create. Then each value in concurIterable is added to the accumulator and the current accumulator is updated using RawAsyncReducerWithoutFinish.add. Finally, the resulting accumulator is transformed using RawAsyncReducerWithFinish.finish if specified. Multiple accumulators may be created, added to, and then combined if supported via RawAsyncReducerWithoutFinish.combine and the next value of concurIterable is ready before promises from RawAsyncReducerWithoutFinish.add resolve.

If asyncReducer is an async optional reducer (no RawAsyncReducerWithoutFinish.create method), then an empty concur iterable is returned if concurIterable is empty. Otherwise, an concur iterable containing the result of reducing using the first value of the concur iterable as the initial accumulator is returned.

Like Array.prototype.reduce, but for concur iterables.

Example

console.log(
await pipe(
asAsync([`Hello`, `World!`, `What`, `an`, `interesting`, `program!`]),
reduceAsync((a, b) => `${a} ${b}`),
getAsync,
),
)
//=> Hello World! What an interesting program!

console.log(
await pipe(
asAsync([`Hello`, `World!`, `What`, `an`, `interesting`, `program!`]),
reduceAsync({ create: () => ``, add: (a, b) => `${a} ${b}` }),
),
)
//=> Hello World! What an interesting program!

Since

v0.0.1

Call Signature

reduceConcur<Value, Acc, Finished, This>(asyncReducer, concurIterable): Promise<Finished>

Type Parameters

Value

Acc

Finished

This

Parameters

asyncReducer

RawAsyncReducerWithFinish<Value, Acc, Finished, This> | RawReducerWithFinish<Value, Acc, Finished, This>

concurIterable

ConcurIterable<Value>

Returns

Promise<Finished>

Defined in

reducers.d.ts:841

Call Signature

reduceConcur<Value, Acc, Finished, This>(asyncReducer): (concurIterable) => Promise<Finished>

Type Parameters

Value

Acc

Finished

This

Parameters

asyncReducer

RawAsyncReducerWithFinish<Value, Acc, Finished, This> | RawReducerWithFinish<Value, Acc, Finished, This>

Returns

Function

Parameters

concurIterable

ConcurIterable<Value>

Returns

Promise<Finished>

Defined in

reducers.d.ts:847

Call Signature

reduceConcur<Value, Acc, This>(asyncReducer, concurIterable): Promise<Acc>

Type Parameters

Value

Acc

This

Parameters

asyncReducer

RawAsyncReducerWithoutFinish<Value, Acc, This> | RawReducerWithoutFinish<Value, Acc, This>

concurIterable

ConcurIterable<Value>

Returns

Promise<Acc>

Defined in

reducers.d.ts:853

Call Signature

reduceConcur<Value, Acc, This>(asyncReducer): (concurIterable) => Promise<Acc>

Type Parameters

Value

Acc

This

Parameters

asyncReducer

RawAsyncReducerWithoutFinish<Value, Acc, This> | RawReducerWithoutFinish<Value, Acc, This>

Returns

Function

Parameters

concurIterable

ConcurIterable<Value>

Returns

Promise<Acc>

Defined in

reducers.d.ts:859

Call Signature

reduceConcur<Value, Finished, This>(asyncReducer, concurIterable): ConcurOptional<Finished>

Type Parameters

Value

Finished

This

Parameters

asyncReducer

RawAsyncOptionalReducerWithFinish<Value, Finished, This> | RawOptionalReducerWithFinish<Value, Finished, This>

concurIterable

ConcurIterable<Value>

Returns

ConcurOptional<Finished>

Defined in

reducers.d.ts:865

Call Signature

reduceConcur<Value, Finished, This>(asyncReducer): (concurIterable) => ConcurOptional<Finished>

Type Parameters

Value

Finished

This

Parameters

asyncReducer

RawAsyncOptionalReducerWithFinish<Value, Finished, This> | RawOptionalReducerWithFinish<Value, Finished, This>

Returns

Function

Parameters

concurIterable

ConcurIterable<Value>

Returns

ConcurOptional<Finished>

Defined in

reducers.d.ts:871

Call Signature

reduceConcur<Value, This>(asyncReducer, concurIterable): ConcurOptional<Value>

Type Parameters

Value

This

Parameters

asyncReducer

RawAsyncOptionalReducerWithoutFinish<Value, This> | RawOptionalReducerWithoutFinish<Value, This>

concurIterable

ConcurIterable<Value>

Returns

ConcurOptional<Value>

Defined in

reducers.d.ts:877

Call Signature

reduceConcur<Value, This>(asyncReducer): (concurIterable) => ConcurOptional<Value>

Type Parameters

Value

This

Parameters

asyncReducer

RawAsyncOptionalReducerWithoutFinish<Value, This> | RawOptionalReducerWithoutFinish<Value, This>

Returns

Function

Parameters

concurIterable

ConcurIterable<Value>

Returns

ConcurOptional<Value>

Defined in

reducers.d.ts:883

Call Signature

reduceConcur<Value>(asyncReducer, concurIterable): ConcurOptional<Value>

Type Parameters

Value

Parameters

asyncReducer

FunctionReducer<Value> | AsyncFunctionReducer<Value>

concurIterable

ConcurIterable<Value>

Returns

ConcurOptional<Value>

Defined in

reducers.d.ts:889

Call Signature

reduceConcur<Value>(asyncReducer): (concurIterable) => ConcurOptional<Value>

Type Parameters

Value

Parameters

asyncReducer

AsyncFunctionReducer<Value> | FunctionReducer<Value>

Returns

Function

Parameters

concurIterable

ConcurIterable<Value>

Returns

ConcurOptional<Value>

Defined in

reducers.d.ts:893