import * as tsplus_module_1 from "@effect/core/stream/Channel/operations/write";
import * as tsplus_module_2 from "@effect/core/stream/Channel/operations/zipRight";
import * as tsplus_module_3 from "@tsplus/stdlib/data/Maybe/fold";
import * as tsplus_module_4 from "@effect/core/stream/Channel/operations/fail";
import * as tsplus_module_5 from "@effect/core/stream/Channel/operations/succeedNow";
import * as tsplus_module_6 from "@effect/core/stream/Channel/operations/readWith";
import * as tsplus_module_7 from "@effect/core/stream/Channel/operations/pipeTo";
/**
 * Returns a new channel, which is the same as this one, except its outputs
 * are filtered and transformed by the specified partial function.
 *
 * @tsplus fluent ets/Channel collect
 */

export function collect_(self, pf) {
  const collector = tsplus_module_6.readWith(out => tsplus_module_3.fold_(pf(out), () => collector, out2 => tsplus_module_2.zipRight_(tsplus_module_1.write(() => out2), () => collector)), e => tsplus_module_4.fail(() => e), z => tsplus_module_5.succeedNow(z));
  return tsplus_module_7.pipeTo_(self, () => collector);
}
/**
 * Returns a new channel, which is the same as this one, except its outputs
 * are filtered and transformed by the specified partial function.
 *
 * @tsplus static ets/Channel/Aspects collect
 */

export const collect = pf => self => collect_(self, pf);
//# sourceMappingURL=collect.mjs.map