Skip to main content

Function: allAsync()

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

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

Example

import { allAsync, 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`]),
allAsync(async word => (await getPartsOfSpeech(word)).includes(`verb`)),
),
)
//=> true

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

Since

v0.0.1

Call Signature

allAsync<Value>(fn): (asyncIterable) => Promise<boolean>

Type Parameters

Value

Parameters

fn

(value) => unknown

Returns

Function

Parameters

asyncIterable

AsyncIterable<Value, any, any>

Returns

Promise<boolean>

Defined in

predicates.d.ts:102

Call Signature

allAsync<Value>(fn, asyncIterable): Promise<boolean>

Type Parameters

Value

Parameters

fn

(value) => unknown

asyncIterable

AsyncIterable<Value, any, any>

Returns

Promise<boolean>

Defined in

predicates.d.ts:102