import * as T from "../_internal/task"; import { Managed } from "../model"; /** * Applies the function `f` to each element of the `Iterable` and * returns the results in a new `B[]`. * * For a parallel version of this method, see `foreachPar`. * If you do not need the results, see `foreachUnit` for a more efficient implementation. */ export const traverseI = (f: (a: A) => Managed) => (as: Iterable) => traverseI_(as, f); /** * Applies the function `f` to each element of the `Iterable` and * returns the results in a new `B[]`. * * For a parallel version of this method, see `foreachPar_`. * If you do not need the results, see `foreachUnit_` for a more efficient implementation. */ export const traverseI_ = (as: Iterable, f: (a: A) => Managed) => new Managed( T.map_( T.traverseI_(as, (a) => f(a).task), (res) => { const fins = res.map((k) => k[0]); const as = res.map((k) => k[1]); return [(e) => T.traverseI_(fins.reverse(), (fin) => fin(e)), as]; } ) );