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

Function takeRemainderLoop

packages/effect/src/PubSub.ts:1330–1361  ·  view source on GitHub ↗
(
  self: Subscription<A>,
  min: number,
  max: number,
  acc: Array<A>
)

Source from the content-addressed store, hash-verified

1328)
1329
1330const takeRemainderLoop = <A>(
1331 self: Subscription<A>,
1332 min: number,
1333 max: number,
1334 acc: Array<A>
1335): Effect.Effect<Array<A>> => {
1336 if (max < min) {
1337 return Effect.succeed(acc)
1338 }
1339 return Effect.flatMap(takeUpTo(self, max), (bs) => {
1340 acc.push(...bs)
1341 const remaining = min - bs.length
1342 if (remaining === 1) {
1343 return Effect.map(take(self), (b) => {
1344 acc.push(b)
1345 return acc
1346 })
1347 }
1348 if (remaining > 1) {
1349 return Effect.flatMap(take(self), (b) => {
1350 acc.push(b)
1351 return takeRemainderLoop(
1352 self,
1353 remaining - 1,
1354 max - bs.length - 1,
1355 acc
1356 )
1357 })
1358 }
1359 return Effect.succeed(acc)
1360 })
1361}
1362
1363/**
1364 * Returns the number of messages currently available in the subscription as an

Callers 1

PubSub.tsFile · 0.85

Calls 4

pushMethod · 0.80
takeFunction · 0.70
succeedMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected