Skip to main content

Type Alias: ConcurIterable<Value>

ConcurIterable<Value> = object

Defined in: core.d.ts:385

Represents a lazy collection of values, each of type Value, that can be iterated concurrently.

The collection can be iterated by invoking the concur iterable's concurIteratorSymbol function with an apply callback. The callback is applied to each value in the collection, potentially asynchronously, in some order.

Invoking the concur iterable's concurIteratorSymbol function returns a promise that resolves when apply has been applied to each value in the concur iterable and each result returned by apply is awaited.

A concur iterable is effectively a cold push-based observable backed by some asynchronous operations.

Example

import { asConcur, concurIteratorSymbol, mapConcur, pipe } from 'lfi'

const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`

const concurIterable = pipe(
asConcur([`sloth`, `lazy`, `sleep`]),
mapConcur(async word => {
const response = await fetch(`${API_URL}/${word}`)
return (await response.json())[0].phonetic
}),
)

await concurIterable[concurIteratorSymbol](console.log)
// NOTE: This order may change between runs
//=> /slɑθ/
//=> /ˈleɪzi/
//=> /sliːp/
Playground

Since

v0.0.2

Type Parameters

Value

Value

Properties

[concurIteratorSymbol]()

[concurIteratorSymbol]: (apply) => Promise<void>

Defined in: core.d.ts:386

Parameters

apply

ConcurIterableApply<Value>

Returns

Promise<void>