| 1401 | * @since 4.0.0 |
| 1402 | */ |
| 1403 | export const reduceArray = <S, In>( |
| 1404 | initial: LazyArg<S>, |
| 1405 | f: (s: S, input: NonEmptyReadonlyArray<In>) => S |
| 1406 | ): Sink<S, In> => |
| 1407 | fromTransform((upstream) => { |
| 1408 | let state = initial() |
| 1409 | return upstream.pipe( |
| 1410 | Effect.flatMap((arr) => { |
| 1411 | state = f(state, arr) |
| 1412 | return Effect.void |
| 1413 | }), |
| 1414 | Effect.forever({ disableYield: true }), |
| 1415 | Pull.catchDone(() => Effect.succeed([state] as const)) |
| 1416 | ) |
| 1417 | }) |
| 1418 | |
| 1419 | /** |
| 1420 | * A sink that reduces its inputs using the provided effectful function `f` |