Packages

class TypeBoundMap[TypeBound, Key[_ <: TypeBound], Val[_ <: TypeBound]] extends BaseTypeBoundMap[TypeBound, Key, Val]

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:

trait Pet
case class Cat(name: String) extends Pet
case class Dog(name: String) extends Pet
class PetStore[P <: Pet]

val catStore1 = new PetStore[Cat]
val catStore2 = new PetStore[Cat]
val dogStore1 = new PetStore[Dog]

we can use a TypeBoundMap to store a list of pets of the appropriate type for every pet store:

var inventories = TypeBoundMap[Pet, PetStore, List]
inventories += (catStore1 -> List(Cat("cat11"), Cat("cat12"), Cat("cat13")))
inventories += (catStore2 -> List(Cat("cat21")))
inventories += (dogStore1 -> List(Dog("dog11"), Dog("dog12")))

now we can look up pet lists by pet store, with everything coming back as the expected type:

val cats1: List[Cat] = inventories(catStore1)
cats1.size should be (3)
val cats2: List[Cat] = inventories(catStore2)
cats2.size should be (1)
val dogs1: List[Dog] = inventories(dogStore1)
dogs1.size should be (2)

val cat: Cat = inventories(catStore1).head
cat should equal (Cat("cat11"))
val dog: Dog = inventories(dogStore1).head
dog should equal (Dog("dog11"))

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.)

TypeBound

the upper bound on the type parameters passed to the Key and Val types

Key

the parameterized type of the keys in the map

Val

the parameterized type of the values in the map

See also

src/test/scala/typekey/typeBoundMap/ for many more examples

Linear Supertypes
BaseTypeBoundMap[TypeBound, Key, Val], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. TypeBoundMap
  2. BaseTypeBoundMap
  3. AnyRef
  4. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. def +[TypeParam <: TypeBound, ValTypeParam <: TypeBound](pair: (Key[TypeParam], Val[ValTypeParam]))(implicit valConforms: <:<[Val[ValTypeParam], Val[TypeParam]]): TypeBoundMap[TypeBound, Key, Val]

    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.

    TypeParam

    the type param bounding both the key and the value

    ValTypeParam

    the type param for the value type. this can be any type, provided that Val[ValTypeParam] <: Val[KeyTypeParam])

    pair

    the key/value pair

    valConforms

    a constraint ensuring that Val[ValTypeParam] <: Val[TypeParam])

  4. def ++(that: TypeBoundMap[TypeBound, Key, Val]): TypeBoundMap[TypeBound, Key, Val]

    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

    that

    the type bound map to union with this type bound map

    returns

    a new type bound map with the bindings of this map and that map

  5. def ->[B](y: B): (TypeBoundMap[TypeBound, Key, Val], B)
    Implicit
    This member is added by an implicit conversion from TypeBoundMap[TypeBound, Key, Val] to ArrowAssoc[TypeBoundMap[TypeBound, Key, Val]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  6. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  7. def apply[TypeParam <: TypeBound](key: Key[TypeParam]): Val[TypeParam]

    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.

    TypeParam

    the type param binding both the key and the value

  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. def contains(key: Key[_ <: TypeBound]): Boolean

    tests whether this map contains a binding for a key.

    tests whether this map contains a binding for a key.

    key

    the key

    returns

    true if there is a binding for key in this map, false otherwise.

    Definition Classes
    BaseTypeBoundMap
  11. def ensuring(cond: (TypeBoundMap[TypeBound, Key, Val]) ⇒ Boolean, msg: ⇒ Any): TypeBoundMap[TypeBound, Key, Val]
    Implicit
    This member is added by an implicit conversion from TypeBoundMap[TypeBound, Key, Val] to Ensuring[TypeBoundMap[TypeBound, Key, Val]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. def ensuring(cond: (TypeBoundMap[TypeBound, Key, Val]) ⇒ Boolean): TypeBoundMap[TypeBound, Key, Val]
    Implicit
    This member is added by an implicit conversion from TypeBoundMap[TypeBound, Key, Val] to Ensuring[TypeBoundMap[TypeBound, Key, Val]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def ensuring(cond: Boolean, msg: ⇒ Any): TypeBoundMap[TypeBound, Key, Val]
    Implicit
    This member is added by an implicit conversion from TypeBoundMap[TypeBound, Key, Val] to Ensuring[TypeBoundMap[TypeBound, Key, Val]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: Boolean): TypeBoundMap[TypeBound, Key, Val]
    Implicit
    This member is added by an implicit conversion from TypeBoundMap[TypeBound, Key, Val] to Ensuring[TypeBoundMap[TypeBound, Key, Val]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. def equals(that: Any): Boolean

    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.

    that

    the other type key map

    returns

    true if both maps contain exactly the same mappings, false otherwise.

    Definition Classes
    TypeBoundMap → AnyRef → Any
  17. def filter(p: (TypeBoundPair[TypeBound, Key, Val, _ <: TypeBound]) ⇒ Boolean): TypeBoundMap[TypeBound, Key, Val]

    selects all elements of this TypeBoundMap which satisfy a predicate

    selects all elements of this TypeBoundMap which satisfy a predicate

    p

    the predicate used to test elements

    returns

    a new TypeBoundMap consisting of all elements of this TypeBoundMap that satisfy the given predicate p. the order of the elements is preserved.

  18. def filterKeys(p: (Key[_ <: TypeBound]) ⇒ Boolean): TypeBoundMap[TypeBound, Key, Val]

    filters this map by retaining only keys satisfying a predicate

    filters this map by retaining only keys satisfying a predicate

    p

    the predicate used to test keys

    returns

    an immutable map consisting only of those key value pairs of this map where the key satisfies the predicate p

  19. def filterNot(p: (TypeBoundPair[TypeBound, Key, Val, _ <: TypeBound]) ⇒ Boolean): TypeBoundMap[TypeBound, Key, Val]

    selects all elements of this TypeBoundMap which do not satisfy a predicate

    selects all elements of this TypeBoundMap which do not satisfy a predicate

    p

    the predicate used to test elements

    returns

    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.

  20. def filterValues(p: (Val[_ <: TypeBound]) ⇒ Boolean): TypeBoundMap[TypeBound, Key, Val]

    filters this map by retaining only values satisfying a predicate

    filters this map by retaining only values satisfying a predicate

    p

    the predicate used to test values

    returns

    an immutable map consisting only of those key value pairs of this map where the value satisfies the predicate p

  21. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  22. def foreach(f: (TypeBoundPair[TypeBound, Key, Val, _ <: TypeBound]) ⇒ Unit): Unit

    [use case] applies a function f to all elements of this type bound map.

    [use case]

    applies a function f to all elements of this type bound map.

    f

    the function that is applied for its side-effect to every element. the result of function f is discarded

    Definition Classes
    BaseTypeBoundMap
    Full Signature

    def foreach[U](f: (TypeBoundPair[TypeBound, Key, Val, _ <: TypeBound]) ⇒ U): Unit

  23. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from TypeBoundMap[TypeBound, Key, Val] to StringFormat[TypeBoundMap[TypeBound, Key, Val]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  24. def get[TypeParam <: TypeBound](key: Key[TypeParam]): Option[Val[TypeParam]]

    optionally returns the value associated with the given key

    optionally returns the value associated with the given key

    TypeParam

    the type param bounding both the key and the value

    returns

    an option value containing the value associated with type key in this map, or None if none exists.

  25. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  26. def getOrElse[TypeParam <: TypeBound](key: Key[TypeParam], default: ⇒ Val[TypeParam]): Val[TypeParam]

    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.

    TypeParam

    the type param bounding both the key and the value

    default

    a computation that yields a default value in case no binding for the key is found in the map

    returns

    the value associated with key if it exists, otherwise the result of the default computation.

  27. def hashCode(): Int
    Definition Classes
    TypeBoundMap → BaseTypeBoundMap → AnyRef → Any
  28. def isEmpty: Boolean

    tests whether the map is empty.

    tests whether the map is empty.

    returns

    true if the map does not contain any key/value binding, false otherwise.

    Definition Classes
    BaseTypeBoundMap
  29. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  30. def iterator: Iterator[TypeBoundPair[TypeBound, Key, Val, _ <: TypeBound]]

    creates a new iterator over all key/value pairs of this map

    creates a new iterator over all key/value pairs of this map

    returns

    the new iterator

    Definition Classes
    BaseTypeBoundMap
  31. def keys: Iterable[Key[_ <: TypeBound]]

    collects all keys of this map in an iterable collection.

    collects all keys of this map in an iterable collection.

    returns

    the keys of this map as an iterable.

    Definition Classes
    BaseTypeBoundMap
  32. def mapValues[Val2[_ <: TypeBound]](f: TypeBoundFunction[TypeBound, Val, Val2]): TypeBoundMap[TypeBound, Key, Val2]

    transforms this map by applying a function to every retrieved value.

    transforms this map by applying a function to every retrieved value.

    f

    the function used to transform values of this map.

    returns

    a map which maps every key of this map to f(this(key)).

  33. def mapValuesUnderlying[TypeBound2 >: TypeBound, Val2[_ <: TypeBound2]](f: WideningTypeBoundFunction[TypeBound, TypeBound2, Val, Val2]): Map[Any, Any]
    Attributes
    protected
    Definition Classes
    BaseTypeBoundMap
  34. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  35. final def notify(): Unit
    Definition Classes
    AnyRef
  36. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  37. def size: Int

    the number of key/value bindings in this map

    the number of key/value bindings in this map

    Definition Classes
    BaseTypeBoundMap
  38. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  39. def toString(): String

    a string representation of a TypeBoundMap

    a string representation of a TypeBoundMap

    Definition Classes
    TypeBoundMap → AnyRef → Any
  40. val underlying: Map[Any, Any]
    Attributes
    protected
    Definition Classes
    BaseTypeBoundMap
  41. def values: Iterable[Val[_ <: TypeBound]]

    collects all values of this map in an iterable collection.

    collects all values of this map in an iterable collection.

    returns

    the values of this map as an iterable.

    Definition Classes
    BaseTypeBoundMap
  42. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  43. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  44. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  45. def widen[Key2[TypeParam <: TypeBound] >: Key[TypeParam], Val2[TypeParam <: TypeBound] >: Val[TypeParam]]: TypeBoundMap[TypeBound, Key2, Val2]

    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

    Key2

    the new key type

    Val2

    the new value type

  46. def [B](y: B): (TypeBoundMap[TypeBound, Key, Val], B)
    Implicit
    This member is added by an implicit conversion from TypeBoundMap[TypeBound, Key, Val] to ArrowAssoc[TypeBoundMap[TypeBound, Key, Val]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Shadowed Implicit Value Members

  1. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from TypeBoundMap[TypeBound, Key, Val] to any2stringadd[TypeBoundMap[TypeBound, Key, Val]] performed by method any2stringadd in scala.Predef.
    Shadowing
    This implicitly inherited member is shadowed by one or more members in this class.
    To access this member you can use a type ascription:
    (typeBoundMap: any2stringadd[TypeBoundMap[TypeBound, Key, Val]]).+(other)
    Definition Classes
    any2stringadd

Inherited from BaseTypeBoundMap[TypeBound, Key, Val]

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from TypeBoundMap[TypeBound, Key, Val] to any2stringadd[TypeBoundMap[TypeBound, Key, Val]]

Inherited by implicit conversion StringFormat from TypeBoundMap[TypeBound, Key, Val] to StringFormat[TypeBoundMap[TypeBound, Key, Val]]

Inherited by implicit conversion Ensuring from TypeBoundMap[TypeBound, Key, Val] to Ensuring[TypeBoundMap[TypeBound, Key, Val]]

Inherited by implicit conversion ArrowAssoc from TypeBoundMap[TypeBound, Key, Val] to ArrowAssoc[TypeBoundMap[TypeBound, Key, Val]]

Ungrouped