Function
reduceWhileArray
(
initial: LazyArg<S>,
contFn: Predicate<S>,
f: (s: S, input: NonEmptyReadonlyArray<In>) => S
)
Source from the content-addressed store, hash-verified
| 1325 | * @since 4.0.0 |
| 1326 | */ |
| 1327 | export const reduceWhileArray = <S, In>( |
| 1328 | initial: LazyArg<S>, |
| 1329 | contFn: Predicate<S>, |
| 1330 | f: (s: S, input: NonEmptyReadonlyArray<In>) => S |
| 1331 | ): Sink<S, In> => |
| 1332 | fromTransform((upstream) => { |
| 1333 | let state = initial() |
| 1334 | if (!contFn(state)) { |
| 1335 | return Effect.succeed([state] as const) |
| 1336 | } |
| 1337 | return upstream.pipe( |
| 1338 | Effect.flatMap((arr) => { |
| 1339 | state = f(state, arr) |
| 1340 | if (!contFn(state)) { |
| 1341 | return Cause.done() |
| 1342 | } |
| 1343 | return Effect.void |
| 1344 | }), |
| 1345 | Effect.forever({ disableYield: true }), |
| 1346 | Pull.catchDone(() => Effect.succeed([state] as const)) |
| 1347 | ) |
| 1348 | }) |
| 1349 | |
| 1350 | /** |
| 1351 | * A sink that effectfully reduces non-empty input arrays from the provided |
Callers
nothing calls this directly
Tested by
no test coverage detected