Function: allConcur()
Returns a promise that resolves to true
if fn
returns a truthy value or a
promise that resolves to a truthy value for all values of concurIterable
.
Otherwise returns a promise that resolves to false
.
Like Array.prototype.every
, but for concur iterables.
Example
import { allConcur, asConcur, 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(
asConcur([`sloth`, `lazy`, `sleep`]),
allConcur(async word => (await getPartsOfSpeech(word)).includes(`verb`)),
),
)
//=> true
console.log(
await pipe(
asConcur([`sloth`, `lazy`, `sleep`]),
allConcur(async word => (await getPartsOfSpeech(word)).includes(`noun`)),
),
)
//=> false
Since
v0.0.2
Call Signature
allConcur<
Value
>(fn
): (concurIterable
) =>Promise
<boolean
>
Type Parameters
• Value
Parameters
fn
(value
) => unknown
Returns
Function
Parameters
concurIterable
ConcurIterable
<Value
>
Returns
Promise
<boolean
>
Defined in
Call Signature
allConcur<
Value
>(fn
,concurIterable
):Promise
<boolean
>
Type Parameters
• Value
Parameters
fn
(value
) => unknown
concurIterable
ConcurIterable
<Value
>
Returns
Promise
<boolean
>