Packages

class TypeKeyMap[TypeBound, Val[_ <: TypeBound]] extends BaseTypeBoundMap[TypeBound, TypeKey, Val]

a map where the keys are type keys with an upper bound, and the values have a type parameter with the same bound. The key and value of each key/value pair are constrained to match on that type parameter. For example, suppose we are maintaining an inventory of computer parts:

sealed trait ComputerPart
case class Memory(gb: Int) extends ComputerPart
case class CPU(mhz: Double) extends ComputerPart
case class Display(resolution: Int) extends ComputerPart

we can use a TypeKeyMap to store a list of parts for each kind of part:

var partLists = TypeKeyMap[ComputerPart, List]()
partLists += Memory(2) :: Memory(4) :: Memory(8) :: Nil
partLists += CPU(2.2) :: CPU(2.4) :: CPU(2.6) :: Nil
partLists += Display(720) :: Display(1080) :: Nil

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

val memories: List[Memory] = partLists[Memory]
memories.size should be (3)
val cpus: List[CPU] = partLists[CPU]
cpus.size should be (3)
val displays: List[Display] = partLists[Display]
displays.size should be (2)

val cpu: CPU = partLists[CPU].head
cpu should equal (CPU(2.2))
val display: Display = partLists[Display].tail.head
display should equal (Display(1080))

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.

(code presented here is in typekey.typeKeyMap.ScaladocSpec.)

TypeBound

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

Val

the parameterized type of the values in the map

See also

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

Linear Supertypes
BaseTypeBoundMap[TypeBound, TypeKey, Val], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. TypeKeyMap
  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](value: Val[TypeParam])(implicit key: TypeKey[TypeParam]): TypeKeyMap[TypeBound, Val]

    adds a typekey/value pair to this map, returning a new map.

    adds a typekey/value pair to this map, returning a new map. the type key is inferred from the type of the supplied value.

    PLEASE NOTE: using this method when your Val type is contravariant in its type parameter will not do what you might expect! when the compiler infers type parameter [TypeParam <: TypeBound] from an argument of type Contra[TypeParam], where type Contra is defined as, e.g., trait Contra[+T], it's always going to infer TypeBound as the TypeParam. there seems to be nothing I can do within TypeKeyMap to circumvent this. the easiest way to work around this problem is to specify the type key yourself with the alternate method +.

    TypeParam

    the type param

    value

    the value to add to the map

    key

    the type key, which is inferred from the type of value

  4. def +[TypeParam <: TypeBound, ValTypeParam <: TypeBound](pair: (TypeKey[TypeParam], Val[ValTypeParam]))(implicit valConforms: <:<[Val[ValTypeParam], Val[TypeParam]]): TypeKeyMap[TypeBound, Val]

    adds a typekey/value pair to this map, returning a new map.

    adds a typekey/value pair to this map, returning a new map.

    TypeParam

    the type param bounding both the type key and the value

    ValTypeParam

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

    pair

    the typekey/value pair

    valConforms

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

  5. def ++(that: TypeKeyMap[TypeBound, Val]): TypeKeyMap[TypeBound, Val]

    takes the union of two type key maps with the same type params

    takes the union of two type key maps with the same type params

    that

    the type key map to union with this type key map

    returns

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

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

    retrieves the value which is associated with the given type key.

    retrieves the value which is associated with the given type key.

    throws java.util.NoSuchElementException when no value is mapped to the supplied type param.

    TypeParam

    the type param binding both the type key and the value

  9. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  10. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  11. def contains[TypeParam <: TypeBound](implicit arg0: TypeKey[TypeParam]): Boolean

    tests whether this TypeKeyMap contains a binding for a type param

    tests whether this TypeKeyMap contains a binding for a type param

    TypeParam

    the type param binding both the type key and the value

    returns

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

  12. def contains(key: TypeKey[_ <: 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
  13. def ensuring(cond: (TypeKeyMap[TypeBound, Val]) ⇒ Boolean, msg: ⇒ Any): TypeKeyMap[TypeBound, Val]
    Implicit
    This member is added by an implicit conversion from TypeKeyMap[TypeBound, Val] to Ensuring[TypeKeyMap[TypeBound, Val]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  14. def ensuring(cond: (TypeKeyMap[TypeBound, Val]) ⇒ Boolean): TypeKeyMap[TypeBound, Val]
    Implicit
    This member is added by an implicit conversion from TypeKeyMap[TypeBound, Val] to Ensuring[TypeKeyMap[TypeBound, Val]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. def ensuring(cond: Boolean, msg: ⇒ Any): TypeKeyMap[TypeBound, Val]
    Implicit
    This member is added by an implicit conversion from TypeKeyMap[TypeBound, Val] to Ensuring[TypeKeyMap[TypeBound, Val]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. def ensuring(cond: Boolean): TypeKeyMap[TypeBound, Val]
    Implicit
    This member is added by an implicit conversion from TypeKeyMap[TypeBound, Val] to Ensuring[TypeKeyMap[TypeBound, Val]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  17. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. 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 iff both are type key maps and contain exactly the same mappings

    Definition Classes
    TypeKeyMap → AnyRef → Any
  19. def filter(p: (TypeBoundPair[TypeBound, TypeKey, Val, _ <: TypeBound]) ⇒ Boolean): TypeKeyMap[TypeBound, Val]

    selects all elements of this TypeKeyMap which satisfy a predicate

    selects all elements of this TypeKeyMap which satisfy a predicate

    p

    the predicate used to test elements

    returns

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

  20. def filterKeys(p: (TypeKey[_ <: TypeBound]) ⇒ Boolean): TypeKeyMap[TypeBound, 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

  21. def filterNot(p: (TypeBoundPair[TypeBound, TypeKey, Val, _ <: TypeBound]) ⇒ Boolean): TypeKeyMap[TypeBound, Val]

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

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

    p

    the predicate used to test elements

    returns

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

  22. def filterTypeBound[TypeBound2 <: TypeBound](implicit arg0: TypeKey[TypeBound2]): TypeKeyMap[TypeBound2, Val]

    filters this map by retaining only pairs that meet the stricter type bound TypeBound2.

    filters this map by retaining only pairs that meet the stricter type bound TypeBound2. returns a TypeKeyMap with the tighter type bound

    TypeBound2

    the new type bound

  23. def filterValues(p: (Val[_ <: TypeBound]) ⇒ Boolean): TypeKeyMap[TypeBound, 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

  24. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  25. def foreach(f: (TypeBoundPair[TypeBound, TypeKey, 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, TypeKey, Val, _ <: TypeBound]) ⇒ U): Unit

  26. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from TypeKeyMap[TypeBound, Val] to StringFormat[TypeKeyMap[TypeBound, Val]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  27. def get[TypeParam <: TypeBound](implicit arg0: TypeKey[TypeParam]): Option[Val[TypeParam]]

    optionally returns the value associated with the given type key

    optionally returns the value associated with the given type key

    TypeParam

    the type param bounding both the type key and the value

    returns

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

  28. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  29. def getOrElse[TypeParam <: TypeBound](default: ⇒ Val[TypeParam])(implicit arg0: TypeKey[TypeParam]): Val[TypeParam]

    returns the value associated with a type key, or a default value if the type key is not contained in the map.

    returns the value associated with a type key, or a default value if the type key is not contained in the map.

    TypeParam

    the type param bounding both the type key and the value

    default

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

    returns

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

  30. def hashCode(): Int
    Definition Classes
    TypeKeyMap → BaseTypeBoundMap → AnyRef → Any
  31. 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
  32. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  33. def iterator: Iterator[TypeBoundPair[TypeBound, TypeKey, 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
  34. def keys: Iterable[TypeKey[_ <: 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
  35. def mapValues[NewVal[_ <: TypeBound]](f: TypeBoundFunction[TypeBound, Val, NewVal]): TypeKeyMap[TypeBound, NewVal]

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

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

    NewVal

    the new value type for the resulting map

    f

    the function used to transform values of this map

    returns

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

  36. def mapValuesUnderlying[TypeBound2 >: TypeBound, Val2[_ <: TypeBound2]](f: WideningTypeBoundFunction[TypeBound, TypeBound2, Val, Val2]): Map[Any, Any]
    Attributes
    protected
    Definition Classes
    BaseTypeBoundMap
  37. def mapValuesWiden[WiderTypeBound >: TypeBound, NewVal[_ <: WiderTypeBound]](f: WideningTypeBoundFunction[TypeBound, WiderTypeBound, Val, NewVal]): TypeKeyMap[WiderTypeBound, NewVal]

    transforms this type key map into a type key map with a wider type bound by applying a function to every retrieved value

    transforms this type key map into a type key map with a wider type bound by applying a function to every retrieved value

    WiderTypeBound

    the new type bound for the resulting map

    NewVal

    the new value type for the resulting map

    f

    the function used to transform values of this map.

    returns

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

  38. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  39. final def notify(): Unit
    Definition Classes
    AnyRef
  40. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  41. def size: Int

    the number of key/value bindings in this map

    the number of key/value bindings in this map

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

    a string representation of a TypeKeyMap

    a string representation of a TypeKeyMap

    Definition Classes
    TypeKeyMap → AnyRef → Any
  44. val underlying: Map[Any, Any]
    Attributes
    protected
    Definition Classes
    BaseTypeBoundMap
  45. 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
  46. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  47. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  48. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  49. def widen[Val2[TypeParam <: TypeBound] >: Val[TypeParam]]: TypeKeyMap[TypeBound, Val2]

    returns the same TypeKeyMap, but with the value type as a wider type than the original value type

    returns the same TypeKeyMap, but with the value type as a wider type than the original value type

    Val2

    the new value type

  50. def [B](y: B): (TypeKeyMap[TypeBound, Val], B)
    Implicit
    This member is added by an implicit conversion from TypeKeyMap[TypeBound, Val] to ArrowAssoc[TypeKeyMap[TypeBound, 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 TypeKeyMap[TypeBound, Val] to any2stringadd[TypeKeyMap[TypeBound, 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:
    (typeKeyMap: any2stringadd[TypeKeyMap[TypeBound, Val]]).+(other)
    Definition Classes
    any2stringadd

Inherited from BaseTypeBoundMap[TypeBound, TypeKey, Val]

Inherited from AnyRef

Inherited from Any

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

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

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

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

Ungrouped