| 466 | * @since 4.0.0 |
| 467 | */ |
| 468 | export 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. |