Function: uniqueByAsync()
Returns an async iterable containing the values of asyncIterable
in
iteration order, except values for which fn
returns a value awaitable to
the same value are deduplicated.
When values are deduplicated, the value earlier in iteration order wins.
Example
import { asAsync, pipe, reduceAsync, toArray, uniqueByAsync } from 'lfi'
const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
uniqueByAsync(async word => {
const response = await fetch(`${API_URL}/${word}`)
const [{ meanings }] = await response.json()
return meanings[0].partOfSpeech
}),
reduceAsync(toArray()),
),
)
//=> [ 'sloth', 'sleep' ]
Since
v0.0.2
Call Signature
uniqueByAsync<
Value
>(fn
): (asyncIterable
) =>AsyncIterable
<Value
,any
,any
>
Type Parameters
• Value
Parameters
fn
(value
) => unknown
Returns
Function
Parameters
asyncIterable
AsyncIterable
<Value
, any
, any
>
Returns
AsyncIterable
<Value
, any
, any
>
Defined in
Call Signature
uniqueByAsync<
Value
>(fn
,asyncIterable
):AsyncIterable
<Value
,any
,any
>
Type Parameters
• Value
Parameters
fn
(value
) => unknown
asyncIterable
AsyncIterable
<Value
, any
, any
>
Returns
AsyncIterable
<Value
, any
, any
>