Method: Immutable::List#add

Defined in:
lib/immutable/list.rb

#add(item) ⇒ List Also known as: cons

Create a new List with item added at the front. This is a constant time operation.

Examples:

Immutable::List[:b, :c].add(:a)
# => Immutable::List[:a, :b, :c]

Parameters:

  • item (Object)

    The item to add

Returns:



189
190
191
# File 'lib/immutable/list.rb', line 189

def add(item)
  Cons.new(item, self)
end