Skip to main content

Variable: firstAsync()

const firstAsync: <Value>(asyncIterable) => AsyncOptional<Value>

Defined in: splices.d.ts:498

Returns an async iterable containing the first value of asyncIterable, or an empty async iterable if asyncIterable is empty.

Type Parameters

Value

Value

Parameters

asyncIterable

AsyncIterable<Value>

Returns

AsyncOptional<Value>

Example

import { asAsync, firstAsync, mapAsync, orAsync, pipe } from 'lfi'

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

console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
mapAsync(async word => {
const response = await fetch(`${API_URL}/${word}`)
return (await response.json())[0].phonetic
}),
firstAsync,
orAsync(() => `empty`),
),
)
//=> /slɑθ/
Playground

Since

v0.0.1