Hyperlinkv0.8.0-beta.28

MutableList

MutableList.toArrayNconsteffect/MutableList.ts:816
<A>(self: MutableList<A>, n: number): Array<A>

Copies up to n elements from the beginning of the MutableList into a new array without modifying the list.

When to use

Use when you need to inspect or snapshot a bounded prefix of the list without consuming it.

elementstakeN
export const toArrayN = <A>(self: MutableList<A>, n: number): Array<A> => {
  const length = Math.min(n, self.length)
  const out = new Array<A>(length)
  let index = 0
  let bucket = self.head
  while (bucket) {
    for (let i = bucket.offset; i < bucket.array.length; i++) {
      out[index++] = bucket.array[i]
      if (index === length) return out
    }
    bucket = bucket.next
  }
  return out
}
Referenced by 2 symbols