UNPKG

rambdax

Version:

Extended version of Rambda - a lightweight, faster alternative to Ramda

30 lines (23 loc) 628 B
import { mapAsync } from './mapAsync' export async function mapToObjectAsyncFn(fn, list){ let toReturn = {} const innerIterable = async x => { const intermediateResult = await fn(x) if (intermediateResult === false) return toReturn = { ...toReturn, ...intermediateResult, } } await mapAsync(innerIterable, list) return toReturn } export function mapToObjectAsync(fn, list){ if (arguments.length === 1){ return async _list => mapToObjectAsyncFn(fn, _list) } return new Promise((resolve, reject) => { mapToObjectAsyncFn(fn, list).then(resolve) .catch(reject) }) }