Skip to main content

Function: filterMapConcur()

Returns a concur iterable containing the values of concurIterable transformed by fn excluding the values for which fn returns a value awaitable to null or undefined.

Example

import { asConcur, filterMapConcur, pipe, reduceConcur, toArray } from 'lfi'

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

console.log(
await pipe(
asConcur([
{ sloth: `sloth` },
{ sloth: `lazy` },
{ notSloth: `active` },
{ sloth: `sleep` },
{ notSloth: `awake` },
]),
filterMapConcur(async object => {
if (!object.sloth) {
return null
}

const response = await fetch(`${API_URL}/${object.sloth}`)
return (await response.json())[0].phonetic
}),
reduceConcur(toArray()),
),
)
// NOTE: This order may change between runs
//=> [ '/slɑθ/', '/ˈleɪzi/', '/sliːp/' ]
Playground

Since

v0.0.1

Call Signature

filterMapConcur<From, To>(fn): (concurIterable) => ConcurIterable<NonNullable<To>>

Type Parameters

From

To extends [] | unknown[]

Parameters

fn

(value) => MaybePromiseLike<undefined | null | To>

Returns

Function

Parameters

concurIterable

ConcurIterable<From>

Returns

ConcurIterable<NonNullable<To>>

Defined in

filters.d.ts:285

Call Signature

filterMapConcur<From, To>(fn, concurIterable): ConcurIterable<NonNullable<To>>

Type Parameters

From

To extends [] | unknown[]

Parameters

fn

(value) => MaybePromiseLike<undefined | null | To>

concurIterable

ConcurIterable<From>

Returns

ConcurIterable<NonNullable<To>>

Defined in

filters.d.ts:288

Call Signature

filterMapConcur<From, To>(fn): (concurIterable) => ConcurIterable<NonNullable<To>>

Type Parameters

From

To

Parameters

fn

(value) => MaybePromiseLike<undefined | null | To>

Returns

Function

Parameters

concurIterable

ConcurIterable<From>

Returns

ConcurIterable<NonNullable<To>>

Defined in

filters.d.ts:293

Call Signature

filterMapConcur<From, To>(fn, concurIterable): ConcurIterable<NonNullable<To>>

Type Parameters

From

To

Parameters

fn

(value) => MaybePromiseLike<undefined | null | To>

concurIterable

ConcurIterable<From>

Returns

ConcurIterable<NonNullable<To>>

Defined in

filters.d.ts:296