Method: Immutable::Vector#drop

Defined in:
lib/immutable/vector.rb

#drop(n) ⇒ Vector

Drop the first n elements and return the rest in a new Vector.

Examples:

Immutable::Vector["A", "B", "C", "D", "E", "F"].drop(2)
# => Immutable::Vector["C", "D", "E", "F"]

Parameters:

  • n (Integer)

    The number of elements to remove

Returns:

Raises:

  • ArgumentError if n is negative.



711
712
713
714
715
716
# File 'lib/immutable/vector.rb', line 711

def drop(n)
  return self if n == 0
  return self.class.empty if n >= @size
  raise ArgumentError, "attempt to drop negative size" if n < 0
  self.class.new(flatten_suffix(@root, @levels * BITS_PER_LEVEL, n, []))
end