Method: Immutable::List#zip

Defined in:
lib/immutable/list.rb

#zip(others) ⇒ List

Combine two lists by “zipping” them together. The corresponding elements from this List and each of others (that is, the elements with the same indices) will be gathered into lists.

If others contains fewer elements than this list, nil will be used for padding.

Examples:

Immutable::List["A", "B", "C"].zip(Immutable::List[1, 2, 3])
# => Immutable::List[Immutable::List["A", 1], Immutable::List["B", 2], Immutable::List["C", 3]]

Parameters:

  • others (List)

    The list to zip together with this one

Returns:



409
410
411
412
413
414
# File 'lib/immutable/list.rb', line 409

def zip(others)
  LazyList.new do
    next self if empty? && others.empty?
    Cons.new(Cons.new(head, Cons.new(others.head)), tail.zip(others.tail))
  end
end