| 1471 | * @since 4.0.0 |
| 1472 | */ |
| 1473 | export const reduceArray = <S, In>( |
| 1474 | initial: LazyArg<S>, |
| 1475 | f: (s: S, input: NonEmptyReadonlyArray<In>) => S |
| 1476 | ): Sink<S, In> => |
| 1477 | fromTransform((upstream) => { |
| 1478 | let state = initial() |
| 1479 | return upstream.pipe( |
| 1480 | Effect.flatMap((arr) => { |
| 1481 | state = f(state, arr) |
| 1482 | return Effect.void |
| 1483 | }), |
| 1484 | Effect.forever({ disableYield: true }), |
| 1485 | Pull.catchDone(() => Effect.succeed([state] as const)) |
| 1486 | ) |
| 1487 | }) |
| 1488 | |
| 1489 | /** |
| 1490 | * A sink that reduces its inputs using the provided effectful function `f` |