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

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