MCPcopy Index your code
hub / github.com/Effect-TS/effect / takeRemainderLoop

Function takeRemainderLoop

packages/effect/src/internal/pubsub.ts:1080–1112  ·  view source on GitHub ↗
(
  self: Queue.Dequeue<A>,
  min: number,
  max: number,
  acc: Chunk.Chunk<A>
)

Source from the content-addressed store, hash-verified

1078
1079/** @internal */
1080const takeRemainderLoop = <A>(
1081 self: Queue.Dequeue<A>,
1082 min: number,
1083 max: number,
1084 acc: Chunk.Chunk<A>
1085): Effect.Effect<Chunk.Chunk<A>> => {
1086 if (max < min) {
1087 return core.succeed(acc)
1088 }
1089 return pipe(
1090 self.takeUpTo(max),
1091 core.flatMap((bs) => {
1092 const remaining = min - bs.length
1093 if (remaining === 1) {
1094 return pipe(self.take, core.map((b) => pipe(acc, Chunk.appendAll(bs), Chunk.append(b))))
1095 }
1096 if (remaining > 1) {
1097 return pipe(
1098 self.take,
1099 core.flatMap((b) =>
1100 takeRemainderLoop(
1101 self,
1102 remaining - 1,
1103 max - bs.length - 1,
1104 pipe(acc, Chunk.appendAll(bs), Chunk.append(b))
1105 )
1106 )
1107 )
1108 }
1109 return core.succeed(pipe(acc, Chunk.appendAll(bs)))
1110 })
1111 )
1112}
1113
1114/** @internal */
1115class PubSubImpl<in out A> implements PubSub.PubSub<A> {

Callers 1

takeBetweenMethod · 0.70

Calls 3

pipeFunction · 0.70
takeUpToMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected