MCPcopy Create free account
hub / github.com/Effect-TS/effect / reduceWhileArrayEffect

Function reduceWhileArrayEffect

packages/effect/src/Sink.ts:1425–1447  ·  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

1423 * @since 4.0.0
1424 */
1425export const reduceWhileArrayEffect = <S, In, E, R>(
1426 initial: LazyArg<S>,
1427 predicate: Predicate<S>,
1428 f: (s: S, input: NonEmptyReadonlyArray<In>) => Effect.Effect<S, E, R>
1429): Sink<S, In, never, E, R> =>
1430 fromTransform((upstream) => {
1431 let state = initial()
1432 if (!predicate(state)) {
1433 return Effect.succeed([state] as const)
1434 }
1435 return upstream.pipe(
1436 Effect.flatMap((arr) => f(state, arr)),
1437 Effect.flatMap((s) => {
1438 state = s
1439 if (!predicate(state)) {
1440 return Cause.done()
1441 }
1442 return Effect.void
1443 }),
1444 Effect.forever({ disableYield: true }),
1445 Pull.catchDone(() => Effect.succeed([state] as const))
1446 )
1447 })
1448
1449/**
1450 * A sink that reduces its inputs using the provided function `f` starting from

Callers

nothing calls this directly

Calls 7

predicateFunction · 0.85
fromTransformFunction · 0.70
pipeMethod · 0.65
initialFunction · 0.50
fFunction · 0.50
succeedMethod · 0.45
doneMethod · 0.45

Tested by

no test coverage detected