Function
reduceWhileArray
(
initial: LazyArg<S>,
contFn: Predicate<S>,
f: (s: S, input: NonEmptyReadonlyArray<In>) => S
)
Source from the content-addressed store, hash-verified
| 1392 | * @since 4.0.0 |
| 1393 | */ |
| 1394 | export const reduceWhileArray = <S, In>( |
| 1395 | initial: LazyArg<S>, |
| 1396 | contFn: Predicate<S>, |
| 1397 | f: (s: S, input: NonEmptyReadonlyArray<In>) => S |
| 1398 | ): Sink<S, In> => |
| 1399 | fromTransform((upstream) => { |
| 1400 | let state = initial() |
| 1401 | if (!contFn(state)) { |
| 1402 | return Effect.succeed([state] as const) |
| 1403 | } |
| 1404 | return upstream.pipe( |
| 1405 | Effect.flatMap((arr) => { |
| 1406 | state = f(state, arr) |
| 1407 | if (!contFn(state)) { |
| 1408 | return Cause.done() |
| 1409 | } |
| 1410 | return Effect.void |
| 1411 | }), |
| 1412 | Effect.forever({ disableYield: true }), |
| 1413 | Pull.catchDone(() => Effect.succeed([state] as const)) |
| 1414 | ) |
| 1415 | }) |
| 1416 | |
| 1417 | /** |
| 1418 | * A sink that effectfully reduces non-empty input arrays from the provided |
Callers
nothing calls this directly
Tested by
no test coverage detected