// ets_tracing: off import type * as Tp from "../Collections/Immutable/Tuple/index.js" import { identity } from "../Function/index.js" import * as I from "../Iterable/index.js" import type { Effect, RIO } from "./effect.js" import { either } from "./either.js" import { forEach_, forEachPar_, forEachParN_ } from "./excl-forEach.js" import { map_ } from "./map.js" /** * Feeds elements of type `A` to a function `f` that returns an effect. * Collects all successes and failures in a separated fashion. * * @ets_data_first partition_ */ export function partition(f: (a: A) => Effect, __trace?: string) { return (as: Iterable): RIO, Iterable]>> => partition_(as, f, __trace) } /** * Feeds elements of type `A` to a function `f` that returns an effect. * Collects all successes and failures in a separated fashion. */ export function partition_( as: Iterable, f: (a: A) => Effect, __trace?: string ): RIO, Iterable]>> { return map_( forEach_(as, (a) => either(f(a)), __trace), I.partitionMap(identity) ) } /** * Feeds elements of type `A` to a function `f` that returns an effect. * Collects all successes and failures in parallel and returns the result as * a tuple. * * @ets_data_first partitionPar_ */ export function partitionPar( f: (a: A) => Effect, __trace?: string ) { return (as: Iterable): Effect, Iterable]>> => partitionPar_(as, f, __trace) } /** * Feeds elements of type `A` to a function `f` that returns an effect. * Collects all successes and failures in parallel and returns the result as * a tuple. */ export function partitionPar_( as: Iterable, f: (a: A) => Effect, __trace?: string ): Effect, Iterable]>> { return map_( forEachPar_(as, (a) => either(f(a)), __trace), I.partitionMap(identity) ) } /** * Feeds elements of type `A` to a function `f` that returns an effect. * Collects all successes and failures in parallel and returns the result as * a tuple. * * Unlike `partitionPar`, this method will use at most up to `n` fibers. * * @ets_data_first partitionParN_ */ export function partitionParN( n: number, f: (a: A) => Effect, __trace?: string ): (as: Iterable) => Effect, Iterable]>> { return (as) => partitionParN_(as, n, f, __trace) } /** * Feeds elements of type `A` to a function `f` that returns an effect. * Collects all successes and failures in parallel and returns the result as * a tuple. * * Unlike `partitionPar`, this method will use at most up to `n` fibers. */ export function partitionParN_( as: Iterable, n: number, f: (a: A) => Effect, __trace?: string ): Effect, Iterable]>> { return map_( forEachParN_(as, n, (a) => either(f(a)), __trace), I.partitionMap(identity) ) }