// // Copyright 2022 DXOS.org // type Transform = (...args: any) => Promise; /** * Async reducer iteratively applies functions to the given array of elements. */ export const chain = (chain: Transform[]) => async (elements: Promise) => { let result = await elements; for (const part of chain) { result = await Promise.all(result.map(async (element) => await part(element))); } return result; };