Hyperlinkv0.8.0-beta.28

MutableList

MutableList.takeNVoidconsteffect/MutableList.ts:669
<A>(self: MutableList<A>, n: number): void

Removes up to n elements from the beginning of the MutableList without returning them.

When to use

Use to discard a bounded number of values from the head of a MutableList when the removed values are not needed.

Details

If n is less than or equal to zero, or the list is empty, the list is left unchanged. If n is greater than or equal to the current length, the list is cleared.

elementstakeNclear
export const takeNVoid = <A>(self: MutableList<A>, n: number): void => {
  if (n <= 0 || !self.head) return
  n = Math.min(n, self.length)
  if (n === self.length && self.head?.offset === 0 && !self.head.next) {
    clear(self)
    return
  }
  let count = 0
  let chunk: MutableList.Bucket<A> | undefined = self.head
  while (chunk) {
    const size = chunk.array.length - chunk.offset
    if (count + size > n) {
      chunk.offset += n - count
      self.head = chunk
      self.length -= n
      return
    }
    count += size
    chunk = chunk.next
  }
  clear(self)
  return
}
Referenced by 2 symbols