Skip to main content

Function: findConcur()

Returns a concur iterable containing the first value of concurIterable for which fn returns a value awaitable to a truthy value. Otherwise, returns an empty concur iterable.

Like Array.prototype.find, but for concur iterables.

Example

import { asConcur, findConcur, 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`]),
findConcur(async word => (await getPartsOfSpeech(word)).includes(`verb`)),
orConcur(() => `not found!`),
),
)
// NOTE: This word may change between runs
//=> sloth

console.log(
await pipe(
asConcur([`sloth`, `lazy`, `sleep`]),
findConcur(async word => (await getPartsOfSpeech(word)).includes(`adverb`)),
orConcur(() => `not found!`),
),
)
//=> not found!
Playground

Since

v0.0.1

Call Signature

findConcur<Value>(fn): (concurIterable) => ConcurOptional<Value>

Type Parameters

Value

Parameters

fn

(value) => unknown

Returns

Function

Parameters

concurIterable

ConcurIterable<Value>

Returns

ConcurOptional<Value>

Defined in

filters.d.ts:764

Call Signature

findConcur<Value>(fn, concurIterable): ConcurOptional<Value>

Type Parameters

Value

Parameters

fn

(value) => unknown

concurIterable

ConcurIterable<Value>

Returns

ConcurOptional<Value>

Defined in

filters.d.ts:764