Skip to main content

Variable: lastAsync()

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

Defined in: splices.d.ts:593

Returns an async iterable containing the last 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, lastAsync, 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
}),
lastAsync,
orAsync(() => `empty`),
),
)
//=> /sliːp/
Playground

Since

v0.0.1