MCPcopy Create free account
hub / github.com/effect-app/libs / reduceWhile

Function reduceWhile

repos/effect/packages/effect/src/Sink.ts:1218–1245  ·  view source on GitHub ↗
(
  initial: LazyArg<S>,
  predicate: Predicate<S>,
  f: (s: S, input: In) => S
)

Source from the content-addressed store, hash-verified

1216 f: (a: A) => Sink<A1, In1, L1, E1, R1>
1217): Sink<A1, In & In1, L | L1, E | E1, R | R1> =>
1218 fromTransform((upstream, scope) => {
1219 let upstreamDone = false
1220 const pull = Effect.catchCause(upstream, (cause) => {
1221 upstreamDone = true
1222 return Effect.failCause(cause)
1223 })
1224 return Effect.flatMap(
1225 self.transform(pull, scope),
1226 ([a, leftover]) =>
1227 f(a).transform(
1228 Effect.suspend(() => {
1229 if (leftover) {
1230 const arr = leftover as Arr.NonEmptyReadonlyArray<In1>
1231 leftover = undefined
1232 return Effect.succeed(arr)
1233 } else if (upstreamDone) {
1234 return Cause.done()
1235 }
1236 return upstream
1237 }),
1238 scope
1239 )
1240 )
1241 }))
1242
1243/**
1244 * A sink that reduces input elements from the provided `initial` state with
1245 * `f` while the specified `predicate` returns `true`.
1246 *
1247 * @category folding
1248 * @since 4.0.0

Callers 2

Sink.tsFile · 0.85
findFunction · 0.85

Calls 7

initialFunction · 0.85
predicateFunction · 0.85
doneMethod · 0.80
fromTransformFunction · 0.70
pipeMethod · 0.65
fFunction · 0.50
succeedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…