Hyperlinkv0.8.0-beta.28

Sink

Sink.reduceArrayconsteffect/Sink.ts:1373
<S, In>(
  initial: LazyArg<S>,
  f: (s: S, input: NonEmptyReadonlyArray<In>) => S
): Sink<S, In>

A sink that reduces its inputs using the provided function f starting from the specified initial state.

reducing
Source effect/Sink.ts:137315 lines
export const reduceArray = <S, In>(
  initial: LazyArg<S>,
  f: (s: S, input: NonEmptyReadonlyArray<In>) => S
): Sink<S, In> =>
  fromTransform((upstream) => {
    let state = initial()
    return upstream.pipe(
      Effect.flatMap((arr) => {
        state = f(state, arr)
        return Effect.void
      }),
      Effect.forever({ disableYield: true }),
      Pull.catchDone(() => Effect.succeed([state] as const))
    )
  })
Referenced by 4 symbols