Skip to main content

Variable: getConcur()

const getConcur: <Value>(concurIterable) => Promise<Value>

Defined in: optionals.d.ts:282

Returns a promise that resolves to the only value in concurIterable if it contains exactly one value. Otherwise, returns a promise that rejects.

The promise does not necessarily reject if the given concurIterable rejects. Instead this function excludes erroring values when counting the number of values in concurIterable.

Type Parameters​

Value​

Value

Parameters​

concurIterable​

ConcurIterable<Value>

Returns​

Promise<Value>

Example​

import { asConcur, findConcur, getConcur, 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)
}),
getConcur,
)

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
try {
console.log(await findWordWithPartOfSpeech(`adverb`))
} catch {
console.log(`Oh no! It was empty...`)
}
//=> Oh no! It was empty...
Playground

Since​

v0.0.2