Package

emblem

Permalink

package emblem

a collection of utilities for reflecting on types

Source
package.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. emblem
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

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

    Permalink

    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.

    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

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

    Permalink

    a map where the keys are type keys with an upper bound, and the values have a type parameter with the same bound.

    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 emblem.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/emblem/typeKeyMap/ for many more examples

Value Members

  1. object TypeKeyMap

    Permalink
  2. package emblematic

    Permalink

    a collection of tools for describing collections of related data types in a generic and traversable way

  3. package exceptions

    Permalink
  4. object jsonUtil

    Permalink

    general purpose functions for working with JSON

  5. object stringUtil

    Permalink

    generally useful utility functions for working with strings

  6. package typeBound

    Permalink
  7. def typeKey[A](implicit arg0: TypeKey[A]): TypeKey[A]

    Permalink

    returns a TypeKey for the specified type A.

    returns a TypeKey for the specified type A. this method will only work where a TypeTag is implicitly available.

  8. implicit def typeKeyFromTag[A](implicit arg0: scala.reflect.api.JavaUniverse.TypeTag[A]): TypeKey[A]

    Permalink

    an implicit method for producing a TypeKey.

    an implicit method for producing a TypeKey. this method allows type keys to be available implicitly anywhere that the corresponding TypeTag is implicitly available.

Inherited from AnyRef

Inherited from Any

Ungrouped