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

Function reduceWhileArrayEffect

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

1355 * @since 4.0.0
1356 */
1357export const reduceWhileArrayEffect = <S, In, E, R>(
1358 initial: LazyArg<S>,
1359 predicate: Predicate<S>,
1360 f: (s: S, input: NonEmptyReadonlyArray<In>) => Effect.Effect<S, E, R>
1361): Sink<S, In, never, E, R> =>
1362 fromTransform((upstream) => {
1363 let state = initial()
1364 if (!predicate(state)) {
1365 return Effect.succeed([state] as const)
1366 }
1367 return upstream.pipe(
1368 Effect.flatMap((arr) => f(state, arr)),
1369 Effect.flatMap((s) => {
1370 state = s
1371 if (!predicate(state)) {
1372 return Cause.done()
1373 }
1374 return Effect.void
1375 }),
1376 Effect.forever({ disableYield: true }),
1377 Pull.catchDone(() => Effect.succeed([state] as const))
1378 )
1379 })
1380
1381/**
1382 * A sink that reduces its inputs using the provided function `f` starting from

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected