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

Function toArrayN

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

Source from the content-addressed store, hash-verified

562 * @since 4.0.0
563 */
564export const toArrayN = <A>(self: MutableList<A>, n: number): Array<A> => {
565 if (n <= 0) return []
566 const length = Math.min(n, self.length)
567 const out = new Array<A>(length)
568 let index = 0
569 let bucket = self.head
570 while (bucket) {
571 for (let i = bucket.offset; i < bucket.array.length; i++) {
572 out[index++] = bucket.array[i]
573 if (index === length) return out
574 }
575 bucket = bucket.next
576 }
577 return out
578}
579
580/**
581 * Copies all current elements of the `MutableList` into a new array without

Callers 1

toArrayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected