| 562 | * @since 4.0.0 |
| 563 | */ |
| 564 | export 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 |