Function: uniqueByConcur()
Returns a concur iterable containing the values of concurIterable
, 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 { asConcur, pipe, reduceConcur, toArray, uniqueByConcur } from 'lfi'
const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
console.log(
await pipe(
asConcur([`sloth`, `lazy`, `sleep`]),
uniqueByConcur(async word => {
const response = await fetch(`${API_URL}/${word}`)
const [{ meanings }] = await response.json()
return meanings[0].partOfSpeech
}),
reduceConcur(toArray()),
),
)
// NOTE: These words may change between runs
//=> [ 'sloth', 'sleep' ]
Since
v0.0.2
Call Signature
uniqueByConcur<
Value
>(fn
): (concurIterable
) =>ConcurIterable
<Value
>
Type Parameters
• Value
Parameters
fn
(value
) => unknown
Returns
Function
Parameters
concurIterable
ConcurIterable
<Value
>
Returns
ConcurIterable
<Value
>
Defined in
Call Signature
uniqueByConcur<
Value
>(fn
,concurIterable
):ConcurIterable
<Value
>
Type Parameters
• Value
Parameters
fn
(value
) => unknown
concurIterable
ConcurIterable
<Value
>
Returns
ConcurIterable
<Value
>