MCPcopy Create free account
hub / github.com/Effect-TS/effect / foldWeightedDecomposeEffectLoop

Function foldWeightedDecomposeEffectLoop

packages/effect/src/internal/sink.ts:1248–1273  ·  view source on GitHub ↗
(
  s: S,
  max: number,
  costFn: (s: S, input: In) => Effect.Effect<number, E, R>,
  decompose: (input: In) => Effect.Effect<Chunk.Chunk<In>, E2, R2>,
  f: (s: S, input: In) => Effect.Effect<S, E3, R3>,
  cost: number,
  dirty: boolean
)

Source from the content-addressed store, hash-verified

1246 })
1247
1248const foldWeightedDecomposeEffectLoop = <S, In, E, R, E2, R2, E3, R3>(
1249 s: S,
1250 max: number,
1251 costFn: (s: S, input: In) => Effect.Effect<number, E, R>,
1252 decompose: (input: In) => Effect.Effect<Chunk.Chunk<In>, E2, R2>,
1253 f: (s: S, input: In) => Effect.Effect<S, E3, R3>,
1254 cost: number,
1255 dirty: boolean
1256): Channel.Channel<Chunk.Chunk<In>, Chunk.Chunk<In>, E | E2 | E3, E | E2 | E3, S, unknown, R | R2 | R3> =>
1257 core.readWith({
1258 onInput: (input: Chunk.Chunk<In>) =>
1259 pipe(
1260 core.fromEffect(foldWeightedDecomposeEffectFold(s, max, costFn, decompose, f, input, dirty, cost, 0)),
1261 core.flatMap(([nextS, nextCost, nextDirty, leftovers]) => {
1262 if (Chunk.isNonEmpty(leftovers)) {
1263 return pipe(core.write(leftovers), channel.zipRight(core.succeedNow(nextS)))
1264 }
1265 if (cost > max) {
1266 return core.succeedNow(nextS)
1267 }
1268 return foldWeightedDecomposeEffectLoop(nextS, max, costFn, decompose, f, nextCost, nextDirty)
1269 })
1270 ),
1271 onFailure: core.fail,
1272 onDone: () => core.succeedNow(s)
1273 })
1274
1275/** @internal */
1276const foldWeightedDecomposeEffectFold = <S, In, E, R, E2, R2, E3, R3>(

Callers 1

Calls 4

fromEffectMethod · 0.80
pipeFunction · 0.70
writeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…