Variable: uniqueByAsync()
constuniqueByAsync: {<Value>(fn): (asyncIterable) =>AsyncIterable<Value>; <Value>(fn,asyncIterable):AsyncIterable<Value>; }
Defined in: filters.d.ts:473
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.
Call Signature
<
Value>(fn): (asyncIterable) =>AsyncIterable<Value>
Type Parameters
Value
Value
Parameters
fn
(value) => unknown
Returns
(
asyncIterable):AsyncIterable<Value>
Parameters
asyncIterable
AsyncIterable<Value>
Returns
AsyncIterable<Value>
Call Signature
<
Value>(fn,asyncIterable):AsyncIterable<Value>
Type Parameters
Value
Value
Parameters
fn
(value) => unknown
asyncIterable
AsyncIterable<Value>
Returns
AsyncIterable<Value>
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