import * as tsplus_module_1 from "@tsplus/stdlib/data/Tuple/make";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_3 from "@effect/core/stream/Sink/operations/foldEffect";
import * as tsplus_module_4 from "@effect/core/stream/Sink/operations/map";
/**
 * Creates a sink that effectfully folds elements of type `In` into a
 * structure of type `S` until `max` elements have been folded.
 *
 * Like `foldWeightedEffect`, but with a constant cost function of 1.
 *
 * @tsplus static ets/Sink/Ops foldUntilEffect
 */

export function foldUntilEffect(z, max, f, __tsplusTrace) {
  return tsplus_module_4.map_(tsplus_module_3.foldEffect(() => tsplus_module_1.make(z(), 0), tuple => tuple.get(1) < max, ({
    tuple: [o, count]
  }, i) => tsplus_module_2.map_(f(o, i), s => tsplus_module_1.make(s, count + 1), __tsplusTrace), __tsplusTrace), tuple => tuple.get(0), __tsplusTrace);
}
//# sourceMappingURL=foldUntilEffect.mjs.map