Variable: findLastConcur
const
findLastConcur:FindConcur
Defined in: filters.d.ts:898
Returns a concur iterable containing the last value of concurIterable
for
which fn
returns a value awaitable to a truthy value. Otherwise, returns an
empty concur iterable.
If a non-empty concur iterable is returned, then the returned concur iterable
does not reject, even if the input concurIterable
does and even if the
found value was emitted after an erroring value.
If an empty concur iterable is returned, then it will reject if the input
concurIterable
does.
Like Array.prototype.findLast
, but for concur iterables. The error
semantics are similar to Promise.any
.
WARNING: This function always waits for concurIterable
to finish iterating
because that's the only way to ensure the found value is the last one.
Example
import { asConcur, findLastConcur, orConcur, pipe } from 'lfi'
const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
const getPartsOfSpeech = async word => {
const response = await fetch(`${API_URL}/${word}`)
const [{ meanings }] = await response.json()
return meanings.map(meaning => meaning.partOfSpeech)
}
console.log(
await pipe(
asConcur([`sloth`, `lazy`, `sleep`]),
findLastConcur(async word => (await getPartsOfSpeech(word)).includes(`verb`)),
orConcur(() => `not found!`),
),
)
// NOTE: This word may change between runs
//=> sleep
console.log(
await pipe(
asConcur([`sloth`, `lazy`, `sleep`]),
findLastConcur(async word => (await getPartsOfSpeech(word)).includes(`adverb`)),
orConcur(() => `not found!`),
),
)
//=> not found!
Since
v0.0.2