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

Function collect

packages/effect/src/Queue.ts:1271–1289  ·  view source on GitHub ↗
(self: Dequeue<A, E | Done>)

Source from the content-addressed store, hash-verified

1269 * @since 4.0.0
1270 */
1271export const collect = <A, E>(self: Dequeue<A, E | Done>): Effect<Array<A>, Pull.ExcludeDone<E>> =>
1272 internalEffect.suspend(() => {
1273 const out = Arr.empty<A>()
1274 return internalEffect.as(
1275 Pull.catchDone(
1276 internalEffect.whileLoop({
1277 while: constTrue,
1278 body: constant(takeAll(self)),
1279 step(items: Arr.NonEmptyArray<A>) {
1280 for (let i = 0; i < items.length; i++) {
1281 out.push(items[i])
1282 }
1283 }
1284 }),
1285 () => internalEffect.void
1286 ),
1287 out
1288 )
1289 }) as any
1290
1291/**
1292 * Takes up to `n` messages from the queue.

Callers

nothing calls this directly

Calls 2

constantFunction · 0.90
takeAllFunction · 0.70

Tested by

no test coverage detected