Variable: filterMapAsync()
const
filterMapAsync: {<From
,To
>(fn
): (asyncIterable
) =>AsyncIterable
<NonNullable
<To
>>; <From
,To
>(fn
,asyncIterable
):AsyncIterable
<NonNullable
<To
>>; <From
,To
>(fn
): (asyncIterable
) =>AsyncIterable
<NonNullable
<To
>>; <From
,To
>(fn
,asyncIterable
):AsyncIterable
<NonNullable
<To
>>; }
Defined in: filters.d.ts:226
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.
Call Signature
<
From
,To
>(fn
): (asyncIterable
) =>AsyncIterable
<NonNullable
<To
>>
Type Parameters
From
From
To
To
extends [] | unknown
[]
Parameters
fn
(value
) => MaybePromiseLike
<undefined
| null
| To
>
Returns
(
asyncIterable
):AsyncIterable
<NonNullable
<To
>>
Parameters
asyncIterable
AsyncIterable
<From
>
Returns
AsyncIterable
<NonNullable
<To
>>
Call Signature
<
From
,To
>(fn
,asyncIterable
):AsyncIterable
<NonNullable
<To
>>
Type Parameters
From
From
To
To
extends [] | unknown
[]
Parameters
fn
(value
) => MaybePromiseLike
<undefined
| null
| To
>
asyncIterable
AsyncIterable
<From
>
Returns
AsyncIterable
<NonNullable
<To
>>
Call Signature
<
From
,To
>(fn
): (asyncIterable
) =>AsyncIterable
<NonNullable
<To
>>
Type Parameters
From
From
To
To
Parameters
fn
(value
) => MaybePromiseLike
<undefined
| null
| To
>
Returns
(
asyncIterable
):AsyncIterable
<NonNullable
<To
>>
Parameters
asyncIterable
AsyncIterable
<From
>
Returns
AsyncIterable
<NonNullable
<To
>>
Call Signature
<
From
,To
>(fn
,asyncIterable
):AsyncIterable
<NonNullable
<To
>>
Type Parameters
From
From
To
To
Parameters
fn
(value
) => MaybePromiseLike
<undefined
| null
| To
>
asyncIterable
AsyncIterable
<From
>
Returns
AsyncIterable
<NonNullable
<To
>>
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