Skip to main content

Variable: takeWhileAsync

const takeWhileAsync: SubWhileAsync

Defined in: splices.d.ts:148

Returns an async iterable containing the values of asyncIterable in iteration order up until but not including the first value for which fn returns a value awaitable to a falsy value.

Example

import { asAsync, flatMapAsync, map, pipe, reduceAsync, takeWhileAsync, toArray } from 'lfi'

const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`

console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
flatMapAsync(async word => {
const response = await fetch(`${API_URL}/${word}`)
const [{ meanings }] = await response.json()
return map(meaning => meaning.partOfSpeech, meanings)
}),
takeWhileAsync(partOfSpeech => partOfSpeech.length === 4),
reduceAsync(toArray()),
),
)
//=> [ 'noun', 'verb', 'noun', 'verb' ]
Playground

Since

v0.0.1