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

Function takeNVoid

packages/effect/src/MutableList.ts:468–490  ·  view source on GitHub ↗
(self: MutableList<A>, n: number)

Source from the content-addressed store, hash-verified

466 * @since 4.0.0
467 */
468export const takeNVoid = <A>(self: MutableList<A>, n: number): void => {
469 if (n <= 0 || !self.head) return
470 n = Math.min(n, self.length)
471 if (n === self.length && self.head?.offset === 0 && !self.head.next) {
472 clear(self)
473 return
474 }
475 let count = 0
476 let chunk: MutableList.Bucket<A> | undefined = self.head
477 while (chunk) {
478 const size = chunk.array.length - chunk.offset
479 if (count + size > n) {
480 chunk.offset += n - count
481 self.head = chunk
482 self.length -= n
483 return
484 }
485 count += size
486 chunk = chunk.next
487 }
488 clear(self)
489 return
490}
491
492/**
493 * Takes all elements from the MutableList and returns them as an array.

Callers

nothing calls this directly

Calls 1

clearFunction · 0.70

Tested by

no test coverage detected