Function: findLastAsync()
Returns an async iterable containing the last value of asyncIterable
for
which fn
returns a value awaitable to a truthy value. Otherwise, returns an
empty async iterable.
Example
import { asAsync, findLastAsync, orAsync, 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`]),
findLastAsync(async word => (await getPartsOfSpeech(word)).includes(`verb`)),
orAsync(() => `not found!`),
),
)
//=> sleep
console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
findLastAsync(async word => (await getPartsOfSpeech(word)).includes(`adverb`)),
orAsync(() => `not found!`),
),
)
//=> not found!
Since
v0.0.1
Call Signature
findLastAsync<
Value
>(fn
): (asyncIterable
) =>AsyncOptional
<Value
>
Type Parameters
• Value
Parameters
fn
(value
) => unknown
Returns
Function
Parameters
asyncIterable
AsyncIterable
<Value
, any
, any
>
Returns
AsyncOptional
<Value
>
Defined in
Call Signature
findLastAsync<
Value
>(fn
,asyncIterable
):AsyncOptional
<Value
>
Type Parameters
• Value
Parameters
fn
(value
) => unknown
asyncIterable
AsyncIterable
<Value
, any
, any
>
Returns
AsyncOptional
<Value
>