MCPcopy
hub / github.com/Effect-TS/effect / runManuallyLoop

Function runManuallyLoop

packages/effect/test/Schedule.test.ts:961–1007  ·  view source on GitHub ↗
(
  schedule: Schedule.Schedule<Out, In, Env>,
  state: unknown,
  inputs: Chunk.Chunk<
    readonly [
      number,
      In
    ]
  >,
  acc: Chunk.Chunk<
    readonly [
      number,
      Out
    ]
  >
)

Source from the content-addressed store, hash-verified

959 return runManuallyLoop(schedule, schedule.initial, Chunk.fromIterable(inputs), Chunk.empty())
960}
961const runManuallyLoop = <Env, In, Out>(
962 schedule: Schedule.Schedule<Out, In, Env>,
963 state: unknown,
964 inputs: Chunk.Chunk<
965 readonly [
966 number,
967 In
968 ]
969 >,
970 acc: Chunk.Chunk<
971 readonly [
972 number,
973 Out
974 ]
975 >
976): Effect.Effect<
977 readonly [
978 Chunk.Chunk<
979 readonly [
980 number,
981 Out
982 ]
983 >,
984 Option.Option<Out>
985 ],
986 never,
987 Env
988> => {
989 if (!Chunk.isNonEmpty(inputs)) {
990 return Effect.succeed([Chunk.reverse(acc), Option.none()] as const)
991 }
992 const [offset, input] = Chunk.headNonEmpty(inputs)
993 const rest = Chunk.tailNonEmpty(inputs)
994 return schedule.step(offset, input, state).pipe(
995 Effect.flatMap(([state, out, decision]) => {
996 if (ScheduleDecision.isDone(decision)) {
997 return Effect.succeed([Chunk.reverse(acc), Option.some(out)] as const)
998 }
999 return runManuallyLoop(
1000 schedule,
1001 state,
1002 rest,
1003 acc.pipe(Chunk.prepend([ScheduleIntervals.start(decision.intervals), out] as const))
1004 )
1005 })
1006 )
1007}
1008// TODO(Mike/Max): remove if added to `effect`
1009const scanLeft = <A, B>(self: Chunk.Chunk<A>, b: B, f: (b: B, a: A) => B): Chunk.Chunk<B> => {
1010 const len = self.length

Callers 1

runManuallyFunction · 0.85

Calls 3

startMethod · 0.80
pipeMethod · 0.65
stepMethod · 0.65

Tested by

no test coverage detected