Immutable::Map::Transient(K, V)
Inherits Immutable::Map < Enumerable < Reference < Object
Constructors
new(hash : Hash(K, V) = {} of K => V)
Sourcenew(hash : Hash(K, V) = {} of K => V, &block : K -> V)
Sourcenew(e : Enumerable(Tuple(L, W))) forall L, W
SourceInstance 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}
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"}
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"}
merge(hash : Hash(L, W)) forall L, W
Sourcemerge(map : Map(L, W)) forall L, W
Sourcepersist!
Sourceset(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}