Method: Immutable::List#chunk

Defined in:
lib/immutable/list.rb

#chunk(number) ⇒ List

Split the items in this list in groups of number. Return a list of lists.

Examples:

("a".."o").to_list.chunk(5)
# => Immutable::List[
#      Immutable::List["a", "b", "c", "d", "e"],
#      Immutable::List["f", "g", "h", "i", "j"],
#      Immutable::List["k", "l", "m", "n", "o"]]

Returns:



726
727
728
729
730
731
732
# File 'lib/immutable/list.rb', line 726

def chunk(number)
  LazyList.new do
    next self if empty?
    first, remainder = split_at(number)
    Cons.new(first, remainder.chunk(number))
  end
end