Skip to main content

Function: includesAsync()

Returns a promise that resolves to true if any value of asyncIterable is equal to searchElement using Object.is. Otherwise returns a promise that resolves to false.

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

Example

import { asAsync, flatMapAsync, includesAsync, 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`]),
flatMapAsync(getPartsOfSpeech),
includesAsync(`noun`),
),
)
//=> true

console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
flatMapAsync(getPartsOfSpeech),
includesAsync(`adverb`),
),
)
//=> false
Playground

Since

v0.0.2

Call Signature

includesAsync(searchElement): <Value>(asyncIterable) => Promise<boolean>

Parameters

searchElement

unknown

Returns

Function

Type Parameters

Value

Parameters

asyncIterable

AsyncIterable<Value, any, any>

Returns

Promise<boolean>

Defined in

predicates.d.ts:438

Call Signature

includesAsync<Value>(searchElement, asyncIterable): Promise<boolean>

Type Parameters

Value

Parameters

searchElement

unknown

asyncIterable

AsyncIterable<Value, any, any>

Returns

Promise<boolean>

Defined in

predicates.d.ts:441