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

Function takeRemainderLoop

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

Source from the content-addressed store, hash-verified

1550)
1551
1552const takeRemainderLoop = <A>(
1553 self: Subscription<A>,
1554 min: number,
1555 max: number,
1556 acc: Array<A>
1557): Effect.Effect<Array<A>> => {
1558 if (max < min) {
1559 return Effect.succeed(acc)
1560 }
1561 return Effect.flatMap(takeUpTo(self, max), (bs) => {
1562 for (let i = 0; i < bs.length; i++) {
1563 acc.push(bs[i])
1564 }
1565 const remaining = min - bs.length
1566 if (remaining === 1) {
1567 return Effect.map(take(self), (b) => {
1568 acc.push(b)
1569 return acc
1570 })
1571 }
1572 if (remaining > 1) {
1573 return Effect.flatMap(take(self), (b) => {
1574 acc.push(b)
1575 return takeRemainderLoop(
1576 self,
1577 remaining - 1,
1578 max - bs.length - 1,
1579 acc
1580 )
1581 })
1582 }
1583 return Effect.succeed(acc)
1584 })
1585}
1586
1587/**
1588 * Returns the number of messages currently available in the subscription as an

Callers 1

PubSub.tsFile · 0.85

Calls 4

takeFunction · 0.70
pushMethod · 0.65
succeedMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected