Evidence that type T
has annotation A
, and provides an instance of the annotation.
Provides the annotations of type A
of the fields or constructors of case class-like or sum type T
.
Provides the annotations of type A
of the fields or constructors of case class-like or sum type T
.
If type T
is case class-like, this type class inspects its fields and provides their annotations of type A
. If
type T
is a sum type, its constructor types are looked for annotations.
Type Out
is an HList having the same number of elements as T
(number of fields of T
if T
is case class-like,
or number of constructors of T
if it is a sum type). It is made of None.type
(no annotation on corresponding
field or constructor) and Some[A]
(corresponding field or constructor is annotated).
Method apply
provides an HList of type Out
made of None
(corresponding field or constructor not annotated)
or Some(annotation)
(corresponding field or constructor has annotation annotation
).
Note that annotation types must be case class-like for this type class to take them into account.
Example:
case class First(s: String) case class CC(i: Int, @First("a") s: String) sealed trait Base @First("b") case class BaseI(i: Int) extends Base case class BaseS(s: String) extends Base val ccFirsts = Annotations[First, CC] val baseFirsts = Annotations[First, Base] // ccFirsts.Out is None.type :: Some[First] :: HNil // ccFirsts.apply() is // None :: Some(First("a")) :: HNil // baseFirsts.Out is Some[First] :: None.type :: HNil // baseFirsts.apply() is // Some(First("b")) :: None :: HNil
Provides default values of case class-like types.
Provides default values of case class-like types.
The Out
type parameter is an HList type whose length is the number of fields of T
. Its elements correspond
to the fields of T
, in their original order. It is made of None.type
(no default value for this field) and
Some[...]
(default value available for this field, with ...
the type of the field). Note that None.type
and
Some[...]
are more precise than simply Option[...]
, so that the availability of default values can be used
in type level calculations.
The apply
method returns an HList of type Out
, with None
elements corresponding to no default value available,
and Some(defaultValue)
to default value available for the corresponding fields.
Use like
case class CC(i: Int, s: String = "b") val default = Default[CC] // default.Out is None.type :: Some[String] :: HNil // default() returns // None :: Some("b") :: HNil, // typed as default.Out
Evidence that type
T
has annotationA
, and provides an instance of the annotation.If type
T
has an annotation of typeA
, then an implicitAnnotation[A, T]
can be found, and itsapply
method provides an instance of the annotation.Example: