MCPcopy Create free account
hub / github.com/effect-app/libs / fold

Function fold

repos/effect/packages/effect/src/Sink.ts:723–745  ·  view source on GitHub ↗
(
  s: LazyArg<S>,
  contFn: Predicate<S>,
  f: (s: S, input: In) => Effect.Effect<S, E, R>
)

Source from the content-addressed store, hash-verified

721 * @see {@link forEach} for consuming all input while running an effect for each element
722 *
723 * @category constructors
724 * @since 2.0.0
725 */
726export const drain: Sink<void, unknown> = fromTransform((upstream) =>
727 Pull.catchDone(
728 Effect.forever(upstream, { disableYield: true }),
729 () => endVoid
730 )
731)
732
733/**
734 * A sink that folds its inputs with the provided function, termination
735 * predicate and initial state.
736 *
737 * **When to use**
738 *
739 * Use to accumulate stream input element by element with an effectful step and
740 * stop based on the accumulated state.
741 *
742 * **Details**
743 *
744 * The initial state is evaluated lazily. Each input element is folded with the
745 * effectful function, and the sink continues while `contFn` returns `true`. If
746 * the sink stops in the middle of a pulled array, the remaining elements from
747 * that array are returned as leftovers.
748 *

Callers 3

foldUntilFunction · 0.85
everyFunction · 0.85
someFunction · 0.85

Calls 4

fromTransformFunction · 0.70
pipeMethod · 0.65
fFunction · 0.50
succeedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…