Method: Immutable::List#drop_while

Defined in:
lib/immutable/list.rb

#drop_while {|item| ... } ⇒ List, Enumerator

Return a List which contains all elements starting from the first element for which the block returns nil or false.

Examples:

Immutable::List[1, 3, 5, 7, 6, 4, 2].drop_while { |e| e < 5 }
# => Immutable::List[5, 7, 6, 4, 2]

Yields:

  • (item)

Returns:

  • (List, Enumerator)


308
309
310
311
312
313
314
315
# File 'lib/immutable/list.rb', line 308

def drop_while(&block)
  return enum_for(:drop_while) unless block_given?
  LazyList.new do
    list = self
    list = list.tail while !list.empty? && yield(list.head)
    list
  end
end