Function: filterMapAsync()
Returns an async iterable containing the values of asyncIterable
transformed by fn
in iteration order excluding the values for which fn
returns a value awaitable to null or undefined.
Example
import { asAsync, filterMapAsync, pipe, reduceAsync, toArray } from 'lfi'
const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
console.log(
await pipe(
asAsync([
{ sloth: `sloth` },
{ sloth: `lazy` },
{ notSloth: `active` },
{ sloth: `sleep` },
{ notSloth: `awake` },
]),
filterMapAsync(async object => {
if (!object.sloth) {
return null
}
const response = await fetch(`${API_URL}/${object.sloth}`)
return (await response.json())[0].phonetic
}),
reduceAsync(toArray()),
),
)
//=> [ '/slɑθ/', '/ˈleɪzi/', '/sliːp/' ]
Since
v0.0.1
Call Signature
filterMapAsync<
From
,To
>(fn
): (asyncIterable
) =>AsyncIterable
<NonNullable
<To
>,any
,any
>
Type Parameters
• From
• To extends [] | unknown
[]
Parameters
fn
(value
) => MaybePromiseLike
<undefined
| null
| To
>
Returns
Function
Parameters
asyncIterable
AsyncIterable
<From
, any
, any
>
Returns
AsyncIterable
<NonNullable
<To
>, any
, any
>
Defined in
Call Signature
filterMapAsync<
From
,To
>(fn
,asyncIterable
):AsyncIterable
<NonNullable
<To
>,any
,any
>
Type Parameters
• From
• To extends [] | unknown
[]
Parameters
fn
(value
) => MaybePromiseLike
<undefined
| null
| To
>
asyncIterable
AsyncIterable
<From
, any
, any
>
Returns
AsyncIterable
<NonNullable
<To
>, any
, any
>
Defined in
Call Signature
filterMapAsync<
From
,To
>(fn
): (asyncIterable
) =>AsyncIterable
<NonNullable
<To
>,any
,any
>
Type Parameters
• From
• To
Parameters
fn
(value
) => MaybePromiseLike
<undefined
| null
| To
>
Returns
Function
Parameters
asyncIterable
AsyncIterable
<From
, any
, any
>
Returns
AsyncIterable
<NonNullable
<To
>, any
, any
>
Defined in
Call Signature
filterMapAsync<
From
,To
>(fn
,asyncIterable
):AsyncIterable
<NonNullable
<To
>,any
,any
>
Type Parameters
• From
• To
Parameters
fn
(value
) => MaybePromiseLike
<undefined
| null
| To
>
asyncIterable
AsyncIterable
<From
, any
, any
>
Returns
AsyncIterable
<NonNullable
<To
>, any
, any
>