Function: uniqueAsync()
uniqueAsync<
Value
>(asyncIterable
):AsyncIterable
<Value
,any
,any
>
Returns an async iterable containing the values of asyncIterable
in
iteration order, except values are deduplicated if they are equal using
Object.is
.
Type Parameters
• Value
Parameters
asyncIterable
AsyncIterable
<Value
, any
, any
>
Returns
AsyncIterable
<Value
, any
, any
>
Example
import { asAsync, flatMapAsync, map, pipe, reduceAsync, toArray, uniqueAsync } from 'lfi'
const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
flatMapAsync(async word => {
const response = await fetch(`${API_URL}/${word}`)
const [{ meanings }] = await response.json()
return map(meaning => meaning.partOfSpeech, meanings)
}),
uniqueAsync,
reduceAsync(toArray()),
),
)
//=> [ 'noun', 'verb', 'adjective' ]
Since
v0.0.2