/** * Evaluate each effect in the structure from left to right, collecting the * the successful values and discarding the empty cases. * * @tsplus static effect/core/stm/STM.Ops collect */ export function collect( as: Collection, f: (a: A) => STM, B> ): STM> { return STM.forEach(as, (a) => f(a).unsome).map((chunk) => chunk.compact) } /** * Simultaneously filters and maps the value produced by this effect. * * @tsplus static effect/core/stm/STM.Aspects collect * @tsplus pipeable effect/core/stm/STM collect */ export function collectNow(pf: (a: A) => Maybe) { return (self: STM): STM => self.collectSTM( (_) => STM.succeed(pf(_)) ) }