wvlet.airframe.surface.tag

This code is from com.softwaremill.tagging

Tag instances with arbitrary types. The tags are usually empty traits. Tags have no runtime overhead and are only used at compile-time for additional type safety.

For example:

 class Berry()

 trait Black
 trait Blue

 val berry = new Berry()
 val blackBerry: Berry @@ Black = berry.taggedWith[Black]
 val blueBerry: Berry @@ Blue = berry.taggedWith[Blue]

 // compile error: val anotherBlackBerry: Berry @@ Black = blueBerry

Original idea by Miles Sabin, see: https://gist.github.com/milessabin/89c9b47a91017973a35f

Type members

Classlikes

implicit class Tagger[T](t: T)

Types

type @@[T, +U] = T & Tag[U]
type Tag[+U] = { type Tag <: U; }
type Tagged[T, +U] = T & Tag[U]

Implicits

Implicits

final implicit def Tagger[T](t: T): Tagger[T]
implicit def toTaggedType[A, Tag](obj: A): A @@ Tag