Skip to main content

Variable: anyAsync

const anyAsync: PredicateAsync

Defined in: predicates.d.ts:214

Returns a promise that resolves to true if fn returns a truthy value or a promise that resolves to a truthy value for any value of asyncIterable. Otherwise returns a promise that resolves to false.

Like Array.prototype.some, but for async iterables.

Example

import { anyAsync, asAsync, 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(
asAsync([`sloth`, `lazy`, `sleep`]),
anyAsync(async word => (await getPartsOfSpeech(word)).includes(`noun`)),
),
)
//=> true

console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
anyAsync(async word => (await getPartsOfSpeech(word)).includes(`adverb`)),
),
)
//=> false
Playground

Since

v0.0.1