Class

emblem

TypeKey

Related Doc: package emblem

Permalink

case class TypeKey[A](tag: scala.reflect.api.JavaUniverse.TypeTag[A]) extends Product with Serializable

behaves much like a scala.reflect.runtime.universe.TypeTag, except that it can also be safely used as a key in a hash or a set. Two type keys will be equal if and only if their underlying types are equivalent according to method =:= in scala.reflect.api.Types.Type. The hashCode method does its best to produce unique hash values, and always produces values compatible with equals.

type keys are provided by an implicit method in package emblem, so you can get one implicitly like so:

def foo[A : TypeKey]() = {
  val key = implicitly[TypeKey[A]]
}

or you can get one explicitly like so:

val key = emblem.typeKey[List[String]]

or if you already have a TypeTag at hand:

val tag: TypeTag[A] = ???
val key = TypeKey(tag)
A

the type that we are keying one

tag

the scala-reflect TypeTag for type A

Source
TypeKey.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. TypeKey
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. 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

Instance Constructors

  1. new TypeKey(tag: scala.reflect.api.JavaUniverse.TypeTag[A])

    Permalink

    tag

    the scala-reflect TypeTag for type A

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from TypeKey[A] to any2stringadd[TypeKey[A]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (TypeKey[A], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from TypeKey[A] to ArrowAssoc[TypeKey[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. def <:<(that: TypeKey[_]): Boolean

    Permalink

    shorthand for this.tpe.<:<

  6. def <:<(that: scala.reflect.api.JavaUniverse.Type): Boolean

    Permalink

    shorthand for this.tpe.<:<

  7. def =:=(that: TypeKey[_]): Boolean

    Permalink

    shorthand for this.tpe.=:=

  8. def =:=(that: scala.reflect.api.JavaUniverse.Type): Boolean

    Permalink

    shorthand for this.tpe.=:=

  9. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  11. def castToLowerBound[B](implicit arg0: TypeKey[B]): Option[TypeKey[_ >: B]]

    Permalink

    if B is a lower bound to type A, then return this cast to TypeKey[_ >: B], wrapped in an option.

    if B is a lower bound to type A, then return this cast to TypeKey[_ >: B], wrapped in an option. this method is provided for Scala grammer only, so that you can reuse this type to safely please the compiler into matching types. however, the return value will remain == to this, so it can be reused as a key into a TypeKeyMap. but it will probably not be equal to a TypeKey[_ >: B] generated by other means. in short, the results of this method are for short term use, as keys with the desired type.

    Here's an example how this works:

    val tki = typeKey[Int]
    val tkli = typeKey[List[Int]]
    val tkla = typeKey[List[_]]
    val tksi = typeKey[Set[Int]]
    val keys: List[TypeKey[_]] = List(tki, tkli, tkla, tksi)
    
    // this is how i type:
    
    val lotks: List[Option[TypeKey[_ >: String]]] = keys.map(_.castToLowerBound[String])
    val lotki: List[Option[TypeKey[_ >: Int]]] = keys.map(_.castToLowerBound[Int])
    
    val lotkli: List[Option[TypeKey[_ >: List[Int]]]] = keys.map(_.castToLowerBound[List[Int]])
    val lotkla: List[Option[TypeKey[_ >: List[_]]]] = keys.map(_.castToLowerBound[List[_]])
    
    // this is how i equal:
    
    keys.map(_.castToLowerBound[String]) should equal (List(None, None, None, None))
    keys.map(_.castToLowerBound[Int]) should equal (List(Some(tki), None, None, None))
    
    keys.map(_.castToLowerBound[List[Int]]) should equal (List(None, Some(tkli), Some(tkla), None))
    keys.map(_.castToLowerBound[List[_]]) should equal (List(None, None, Some(tkla), None))
  12. def castToUpperBound[B](implicit arg0: TypeKey[B]): Option[TypeKey[_ <: B]]

    Permalink

    if B is an upper bound to type A, then return this cast to TypeKey[_ <: B], wrapped in an option.

    if B is an upper bound to type A, then return this cast to TypeKey[_ <: B], wrapped in an option. this method is provided for Scala grammer only, so that you can reuse this type to safely please the compiler into matching types. however, the return value will remain == to this, so it can be reused as a key into a TypeKeyMap. but it will probably not be equal to a TypeKey[_ <: B] generated by other means. in short, the results of this method are for short term use, as keys with the desired type.

    Here's an example how this works:

    val tki = typeKey[Int]
    val tkli = typeKey[List[Int]]
    val tkla = typeKey[List[_]]
    val tksi = typeKey[Set[Int]]
    val keys: List[TypeKey[_]] = List(tki, tkli, tkla, tksi)
    
    // this is how i type:
    
    val lotks: List[Option[TypeKey[_ <: String]]] = keys.map(_.castToUpperBound[String])
    val lotki: List[Option[TypeKey[_ <: Int]]] = keys.map(_.castToUpperBound[Int])
    
    val lotkli: List[Option[TypeKey[_ <: List[Int]]]] = keys.map(_.castToUpperBound[List[Int]])
    val lotkla: List[Option[TypeKey[_ <: List[_]]]] = keys.map(_.castToUpperBound[List[_]])
    
    // this is how i equal:
    
    keys.map(_.castToUpperBound[String]) should equal (List(None, None, None, None))
    keys.map(_.castToUpperBound[Int]) should equal (List(Some(tki), None, None, None))
    
    keys.map(_.castToUpperBound[List[Int]]) should equal (List(None, Some(tkli), None, None))
    keys.map(_.castToUpperBound[List[_]]) should equal (List(None, Some(tkli), Some(tkla), None))
  13. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. def ensuring(cond: (TypeKey[A]) ⇒ Boolean, msg: ⇒ Any): TypeKey[A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from TypeKey[A] to Ensuring[TypeKey[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  15. def ensuring(cond: (TypeKey[A]) ⇒ Boolean): TypeKey[A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from TypeKey[A] to Ensuring[TypeKey[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  16. def ensuring(cond: Boolean, msg: ⇒ Any): TypeKey[A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from TypeKey[A] to Ensuring[TypeKey[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  17. def ensuring(cond: Boolean): TypeKey[A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from TypeKey[A] to Ensuring[TypeKey[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  18. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  19. def equals(that: Any): Boolean

    Permalink
    Definition Classes
    TypeKey → Equals → AnyRef → Any
  20. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  21. def formatted(fmtstr: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from TypeKey[A] to StringFormat[TypeKey[A]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  22. def fullname(tpe: scala.reflect.api.JavaUniverse.Type): String

    Permalink

    the full type name for the type represented by this key

  23. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  24. lazy val hashCode: Int

    Permalink
    Definition Classes
    TypeKey → AnyRef → Any
  25. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  26. def name: String

    Permalink

    the simple type name for the type represented by this key

  27. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  28. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  29. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  30. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  31. val tag: scala.reflect.api.JavaUniverse.TypeTag[A]

    Permalink

    the scala-reflect TypeTag for type A

  32. def toString(): String

    Permalink
    Definition Classes
    TypeKey → AnyRef → Any
  33. def tpe: scala.reflect.api.JavaUniverse.Type

    Permalink

    the scala-reflect Type for type A

  34. lazy val typeArgs: List[TypeKey[_]]

    Permalink

    a list of type keys for the type arguments of this type

  35. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  36. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  37. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. def [B](y: B): (TypeKey[A], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from TypeKey[A] to ArrowAssoc[TypeKey[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from TypeKey[A] to any2stringadd[TypeKey[A]]

Inherited by implicit conversion StringFormat from TypeKey[A] to StringFormat[TypeKey[A]]

Inherited by implicit conversion Ensuring from TypeKey[A] to Ensuring[TypeKey[A]]

Inherited by implicit conversion ArrowAssoc from TypeKey[A] to ArrowAssoc[TypeKey[A]]

Ungrouped