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

Function reduceWhileArrayEffect

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

Source from the content-addressed store, hash-verified

1325 * @since 4.0.0
1326 */
1327export const reduceWhileArray = <S, In>(
1328 initial: LazyArg<S>,
1329 contFn: Predicate<S>,
1330 f: (s: S, input: NonEmptyReadonlyArray<In>) => S
1331): Sink<S, In> =>
1332 fromTransform((upstream) => {
1333 let state = initial()
1334 if (!contFn(state)) {
1335 return Effect.succeed([state] as const)
1336 }
1337 return upstream.pipe(
1338 Effect.flatMap((arr) => {
1339 state = f(state, arr)
1340 if (!contFn(state)) {
1341 return Cause.done()
1342 }
1343 return Effect.void
1344 }),
1345 Effect.forever({ disableYield: true }),
1346 Pull.catchDone(() => Effect.succeed([state] as const))
1347 )
1348 })
1349
1350/**
1351 * A sink that effectfully reduces non-empty input arrays from the provided
1352 * `initial` state with `f` while the specified `predicate` returns `true`.

Callers

nothing calls this directly

Calls 7

initialFunction · 0.85
predicateFunction · 0.85
doneMethod · 0.80
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…