class

Immutable::Map::Transient(K, V)

Inherits Immutable::Map < Enumerable < Reference < Object

Constructors

new(hash : Hash(K, V) = {} of K => V)
Source
new(hash : Hash(K, V) = {} of K => V, &block : K -> V)
Source
new(e : Enumerable(Tuple(L, W))) forall L, W
Source

Instance methods

delete(key : K)

Returns a modified copy of the map with the key-value pair removed. If the key is not existing, it raises KeyError

m  = Immutable::Map[{:foo => 123, :bar => 321 }]
m2 = m.delete(:bar) # => Map {:foo => 123}
m                   # => Map {:foo => 123, bar: 321}
Source
merge(hash : Hash(K, V))

Returns a new map with the keys and values of this map and the given hash combined. A value in the given hash takes precedence over the one in this map.

map = Immutable::Map[{"foo" => "bar"}]
merged = map.merge({"baz" => "qux"})
merged # => Map {"foo" => "bar", "baz" => "qux"}
map    # => Map {"foo" => "bar"}
Source
merge(map : Map(K, V))

Returns a new map with the keys and values of this map and the given map combined. A value in the given map takes precedence over the one in this map.

map = Immutable::Map[{"foo" => "bar"}]
merged = map.merge(Immutable::Map[{"baz" => "qux"}])
merged # => Map {"foo" => "bar", "baz" => "qux"}
map    # => Map {"foo" => "bar"}
Source
merge(hash : Hash(L, W)) forall L, W
Source
merge(map : Map(L, W)) forall L, W
Source
persist!
Source
set(key : K, value : V)

Returns a modified copy of the map where key is associated to value

m  = Immutable::Map[{:foo => 123}]
m2 = m.set(:bar, 321) # => Map {:foo => 123, :bar => 321}
m                     # => Map {:foo => 123}
Source

Nested types