adds a key/value pair to this map, returning a new map.
adds a key/value pair to this map, returning a new map. both the key and the value are bound by the same type param.
the type param bounding both the key and the value
the type param for the value type. this can be any type, provided that
Val[ValTypeParam] <: Val[KeyTypeParam])
the key/value pair
a constraint ensuring that Val[ValTypeParam] <: Val[TypeParam])
takes the union of two type bound maps with the same type params
takes the union of two type bound maps with the same type params
the type bound map to union with this type bound map
a new type bound map with the bindings of this map and that map
retrieves the value which is associated with the given key, both bound by the same type param.
retrieves the value which is associated with the given key, both bound by the same type param.
throws java.util.NoSuchElementException when no value is mapped to the supplied key.
the type param binding both the key and the value
tests whether this map contains a binding for a key.
tests whether this map contains a binding for a key.
the key
true
if there is a binding for key in this map, false
otherwise.
compares two maps structurally; i.e., checks if all mappings contained in this map are also contained in the other map, and vice versa.
compares two maps structurally; i.e., checks if all mappings contained in this map are also contained in the other map, and vice versa.
the other type key map
true if both maps contain exactly the same mappings, false otherwise.
selects all elements of this TypeBoundMap which satisfy a predicate
selects all elements of this TypeBoundMap which satisfy a predicate
the predicate used to test elements
a new TypeBoundMap consisting of all elements of this TypeBoundMap
that satisfy the given predicate p
. the order of the elements is
preserved.
filters this map by retaining only keys satisfying a predicate
filters this map by retaining only keys satisfying a predicate
the predicate used to test keys
an immutable map consisting only of those key value pairs of this
map where the key satisfies the predicate p
selects all elements of this TypeBoundMap which do not satisfy a predicate
selects all elements of this TypeBoundMap which do not satisfy a predicate
the predicate used to test elements
a new TypeBoundMap consisting of all elements of this TypeBoundMap
that do not satisfy the given predicate p
. the order of the elements is
preserved.
filters this map by retaining only values satisfying a predicate
filters this map by retaining only values satisfying a predicate
the predicate used to test values
an immutable map consisting only of those key value pairs of this
map where the value satisfies the predicate p
[use case] applies a function f
to all elements of this type bound map.
applies a function f
to all elements of this type bound map.
the function that is applied for its side-effect to every element.
the result of function f
is discarded
optionally returns the value associated with the given key
optionally returns the value associated with the given key
the type param bounding both the key and the value
an option value containing the value associated with type key in
this map, or None
if none exists.
returns the value associated with a key, or a default value if the key is not contained in the map.
returns the value associated with a key, or a default value if the key is not contained in the map.
the type param bounding both the key and the value
a computation that yields a default value in case no binding for the key is found in the map
the value associated with key if it exists, otherwise the result of
the default
computation.
tests whether the map is empty.
tests whether the map is empty.
true
if the map does not contain any key/value binding, false
otherwise.
creates a new iterator over all key/value pairs of this map
creates a new iterator over all key/value pairs of this map
the new iterator
collects all keys of this map in an iterable collection.
collects all keys of this map in an iterable collection.
the keys of this map as an iterable.
transforms this map by applying a function to every retrieved value.
transforms this map by applying a function to every retrieved value.
the function used to transform values of this map.
a map which maps every key of this map to f(this(key))
.
the number of key/value bindings in this map
the number of key/value bindings in this map
a string representation of a TypeBoundMap
a string representation of a TypeBoundMap
collects all values of this map in an iterable collection.
collects all values of this map in an iterable collection.
the values of this map as an iterable.
returns the same TypeBoundMap
, but with the key and value types as wider
types than the originals
returns the same TypeBoundMap
, but with the key and value types as wider
types than the originals
the new key type
the new value type
(typeBoundMap: any2stringadd[TypeBoundMap[TypeBound, Key, Val]]).+(other)
a map where the types for keys and values share a type parameter with the same bounds. the key and value of each key/value pair are constrained to match on that type parameter. for example, we might have some pet stores that only cater to a single kind of pet:
we can use a
TypeBoundMap
to store a list of pets of the appropriate type for every pet store:now we can look up pet lists by pet store, with everything coming back as the expected type:
note that the API does not provide methods to add multiple key/value pairs at a time, as each pair needs to be type-checked separately.
(the code presented here is in test class
typekey.typeBoundMap.ScaladocSpec
.)the upper bound on the type parameters passed to the
Key
andVal
typesthe parameterized type of the keys in the map
the parameterized type of the values in the map
src/test/scala/typekey/typeBoundMap/
for many more examples