Function: orConcur()
Returns a promise that resolves to the only value in concurIterable
if it
contains exactly one value. Otherwise, returns a promise that resolves to
the awaited result of invoking fn
.
Example
import { asConcur, findConcur, orConcur, pipe } from 'lfi'
const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
const findWordWithPartOfSpeech = partOfSpeech =>
pipe(
asConcur([`sloth`, `lazy`, `sleep`]),
findConcur(async word => {
const response = await fetch(`${API_URL}/${word}`)
const [{ meanings }] = await response.json()
return meanings.some(meaning => meaning.partOfSpeech === partOfSpeech)
}),
orConcur(() => `no ${partOfSpeech}???`),
)
console.log(await findWordWithPartOfSpeech(`noun`))
// NOTE: This word may change between runs
//=> sloth
console.log(await findWordWithPartOfSpeech(`verb`))
// NOTE: This word may change between runs
//=> sloth
console.log(await findWordWithPartOfSpeech(`adjective`))
//=> lazy
console.log(await findWordWithPartOfSpeech(`adverb`))
//=> no adverb???
Since
v0.0.2
Call Signature
orConcur<
Value
>(fn
): (concurIterable
) =>Promise
<Value
>
Type Parameters
• Value
Parameters
fn
() => MaybePromiseLike
<Value
>
Returns
Function
Parameters
concurIterable
ConcurIterable
<Value
>
Returns
Promise
<Value
>
Defined in
Call Signature
orConcur<
Value
>(fn
,concurIterable
):Promise
<Value
>
Type Parameters
• Value
Parameters
fn
() => MaybePromiseLike
<Value
>
concurIterable
ConcurIterable
<Value
>
Returns
Promise
<Value
>