package misc
- Alphabetic
- Public
- All
Type Members
-
abstract
class
AbstractCase extends CaseMethods
Base class for case classes that reduces amount of code that the compiler generates for them.
Base class for case classes that reduces amount of code that the compiler generates for them. Useful primarily for JS size reduction. See CaseMethods for more details.
- abstract class AbstractNamedEnumCompanion[T <: NamedEnum] extends AbstractSealedEnumCompanion[T] with NamedEnumCompanion[T]
- abstract class AbstractSealedEnumCompanion[T] extends SealedEnumCompanion[T]
-
abstract
class
AbstractValueEnum extends ValueEnum
Convenience abstract class implementing ValueEnum.
-
abstract
class
AbstractValueEnumCompanion[T <: ValueEnum] extends AbstractNamedEnumCompanion[T] with ValueEnumCompanion[T]
Convenience abstract class implementing ValueEnumCompanion.
Convenience abstract class implementing ValueEnumCompanion. For less generated code, faster compilation and better binary compatibility it's better to use this abstract class rather than ValueEnumCompanion trait directly. See ValueEnum documentation for more information on value based enums.
-
final
case class
AnnotationOf[A, T](annot: A) extends AnyVal with Product with Serializable
- Annotations
- @implicitNotFound( "${T} is not annotated with ${A}" )
- final case class AnnotationsOf[A, T](annots: List[A]) extends AnyVal with Product with Serializable
-
trait
Applier[T] extends AnyRef
Typeclass which captures case class
apply
method in a raw form that takes untyped sequence of arguments.Typeclass which captures case class
apply
method in a raw form that takes untyped sequence of arguments.- Annotations
- @implicitNotFound( ... )
-
trait
ApplierUnapplier[T] extends Applier[T] with Unapplier[T]
- Annotations
- @implicitNotFound( ... )
-
trait
AutoNamedEnum extends NamedEnum with Product
Subtrait of NamedEnum which requires its values to be
Product
s and usesProduct.productPrefix
as the name of each enum constant.Subtrait of NamedEnum which requires its values to be
Product
s and usesProduct.productPrefix
as the name of each enum constant. In practice this means that all the objects extending AutoNamedEnum should becase object
s so that object names are automatically used as enum constant names. That's because case classes and objects automatically implementProduct
and use their source name asProduct.productPrefix
. - final case class Boxing[-A, +B](fun: (A) ⇒ B) extends AnyVal with Product with Serializable
-
case class
Bytes(bytes: Array[Byte]) extends Product with Serializable
General purpose wrapper over byte array which adds
equals
,hashCode
andtoString
which work on array elements instead of object identity. -
trait
CaseMethods extends Product
Implements common case class & case object methods normally synthesized by the compiler.
Implements common case class & case object methods normally synthesized by the compiler. Extending this trait by case class or case object prevents the compiler from synthesizing these methods which can reduce generated JS size at penalty of not-exactly-precise implementation of
canEqual
andequals
and its runtime performance. For this reason, non-abstract classes extending this trait should always be final. If possible, prefer using AbstractCase rather than this trait. -
trait
Delegation[A, B] extends AnyRef
A typeclass which witnesses that type
A
can be wrapped into trait or abstract classB
-
sealed
trait
EnumCtx extends Any
- Annotations
- @implicitNotFound( ... )
-
final
class
HasAnnotation[A, T] extends AnyRef
- Annotations
- @implicitNotFound( "${T} is not annotated with ${A}" )
-
sealed
trait
ImplicitNotFound[T] extends AnyRef
Extends the functionality of scala.annotation.implicitNotFound so that implicit-not-found error message is itself resolved using implicit search.
Extends the functionality of scala.annotation.implicitNotFound so that implicit-not-found error message is itself resolved using implicit search. This mechanism is used by Implicits.infer[T]:T* and macro engines that use it.
Example: we have a wrapper class
Box[T]
and we want a custom error message whenGenCodec[Box[T]]
for some typeT
is not found:trait Box[T] object Box { implicit def boxCodec[T: GenCodec]: GenCodec[Box[T]] = ... @implicitNotFound("GenCodec for Box[$${T}] not found. This is most likely caused by lack of GenCodec[$${T}]") implicit def boxCodecNotFound[T]: ImplicitNotFound[GenCodec[Box[T]]] = ImplicitNotFound() }
It is also possible to compose error message for one type from error messages for other types. The example above could reuse the implicit-not-found message for
GenCodec[T]
when building the message forGenCodec[Box[T]]
:@implicitNotFound("GenCodec for Box[$${T}] not found, because:\n#{forUnboxed}") implicit def boxCodecNotFound[T]( implicit forUnboxed: ImplicitNotFound[GenCodec[T]] ): ImplicitNotFound[GenCodec[Box[T]]] = ImplicitNotFound()
-
final
class
JavaClassName[T] extends AnyVal
Typeclass that contains JVM fully qualified class name corresponding to given type.
Typeclass that contains JVM fully qualified class name corresponding to given type.
JavaClassName.of[T]
is always equal toclassTag[T].runtimeClass.getName
JavaClassName
can be used instead ofClassTag
in ScalaJS when ScalaJS linker is configured to drop class names. Also, unlikeClassTag
,JavaClassName
contains just a string so it can be easily serialized and deserialized. - trait JavaClassNameLowPrio extends AnyRef
- trait LowPrioBoxing extends AnyRef
- trait LowPrioUnboxing extends AnyRef
-
final
class
NOpt[+A] extends AnyVal with Serializable
Like Opt but does have a counterpart for
Some(null)
. -
trait
NamedEnum extends Serializable
Base trait for enums implemented as sealed hierarchy with case objects where every enum value has distinct textual representation (name).
Base trait for enums implemented as sealed hierarchy with case objects where every enum value has distinct textual representation (name).
Typically, if a trait or class extends
NamedEnum
, its companion object extends NamedEnumCompanion. Enum values can then be looked up by name using NamedEnumCompanion.byName. -
trait
NamedEnumCompanion[T <: NamedEnum] extends SealedEnumCompanion[T]
Base trait for companion objects of sealed traits that serve as named enums.
Base trait for companion objects of sealed traits that serve as named enums.
NamedEnumCompanion
is an extension of SealedEnumCompanion which additionally requires that every enum value has distinct string representation. Values can then be looked up by that representation using NamedEnumCompanion.byNameExample:
sealed abstract class Color(val name: String) extends NamedEnum object Color extends NamedEnumCompanion[Color] { case object Red extends Color("red") case object Blue extends Color("blue") case object Green extends Color("green") // it's important to explicitly specify the type so that `caseObjects` macro works properly val values: List[Color] = caseObjects }
NamedEnumCompanion
also automatically provides implicit typeclass instances for GenKeyCodec and GenCodec. -
final
class
Opt[+A] extends AnyVal with Serializable
Like
Option
but implemented as value class (avoids boxing) and treatsnull
as no value.Like
Option
but implemented as value class (avoids boxing) and treatsnull
as no value. Therefore, there is no equivalent forSome(null)
.If you need a value-class version of
Option
which differentiates between no value andnull
value, use NOpt. - case class OptAnnotationOf[A, T](annotOpt: Opt[A]) extends Product with Serializable
-
final
class
OptArg[+A] extends AnyVal with Serializable
OptArg is like Opt except it's intended to be used to type-safely express optional method/constructor parameters while at the same time avoiding having to explicitly wrap arguments when passing them (thanks to the implicit conversion from
A
toOptArg[A]
).OptArg is like Opt except it's intended to be used to type-safely express optional method/constructor parameters while at the same time avoiding having to explicitly wrap arguments when passing them (thanks to the implicit conversion from
A
toOptArg[A]
). For example:def takesMaybeString(str: OptArg[String] = OptArg.Empty) = ??? takesMaybeString() // default empty value is used takesMaybeString("string") // no explicit wrapping into OptArg required
Note that like Opt, OptArg assumes its underlying value to be non-null and
null
is translated intoOptArg.Empty
.
It is strongly recommended that OptArg type is used ONLY in signatures where implicit conversionA => OptArg[A]
is intended to work. You should not use OptArg as a general-purpose "optional value" type - other types like Opt, NOpt andOption
serve that purpose. For this reason OptArg deliberately does not have any "transforming" methods likemap
,flatMap
,orElse
, etc. Instead it's recommended that OptArg is converted to Opt, NOpt orOption
as soon as possible (usingtoOpt
,toNOpt
andtoOption
methods). -
final
class
OptRef[+A >: Null] extends AnyVal with Serializable
Like Opt but has better Java interop thanks to the fact that wrapped value has type
A
instead ofAny
.Like Opt but has better Java interop thanks to the fact that wrapped value has type
A
instead ofAny
. For example, Scala method defined like this:def takeMaybeString(str: OptRef[String]): Unit
will be seen by Java as:
public void takeMaybeString(String str);
and
null
will be used to represent absence of value.This comes at the cost of
A
having to be a nullable type. Also, empty value is represented internally usingnull
which unfortunately makes OptRef suffer from SI-7396 (hashCode
fails onOptRef.Empty
which means that you can't add OptRef values into hash sets or use them as hash map keys). -
trait
OrderedEnum extends AnyRef
Trait to be extended by enums whose values are ordered by declaration order.
Trait to be extended by enums whose values are ordered by declaration order. Ordering is derived from SourceInfo object, which is typically accepted as an implicit, e.g.
sealed abstract class MyOrderedEnum(implicit val sourceInfo: SourceInfo) extends OrderedEnum object MyOrderedEnum { case object First extends MyOrderedEnum case object Second extends MyOrderedEnum case object Third extends MyOrderedEnum val values: List[MyOrderedEnum] = caseObjects }
In the example above,
values
is guaranteed to returnFirst
,Second
andThird
objects in exactly that order. - abstract class ProductApplierUnapplier[T <: Product] extends ProductUnapplier[T] with ApplierUnapplier[T]
- class ProductUnapplier[T <: Product] extends Unapplier[T]
- abstract class SamCompanion[T, F] extends AnyRef
-
trait
SealedEnumCompanion[T] extends AnyRef
Base trait for companion objects of sealed traits that serve as enums, i.e.
Base trait for companion objects of sealed traits that serve as enums, i.e. their only values are case objects. For example:
sealed trait SomeEnum object SomeEnum extends SealedEnumCompanion[SomeEnum] { case object FirstValue extends SomeEnum case object SecondValue extends SomeEnum case object ThirdValue extends SomeEnum // it's important to explicitly specify the type so that `caseObjects` macro works properly val values: List[SomeEnum] = caseObjects }
- final case class SelfAnnotation[A](annot: A) extends AnyVal with Product with Serializable
- final case class SelfAnnotations[A](annots: List[A]) extends AnyVal with Product with Serializable
- case class SelfInstance[C[_]](instance: C[_]) extends Product with Serializable
- case class SelfOptAnnotation[A](annotOpt: Opt[A]) extends Product with Serializable
- final case class SimpleClassName[T](name: String) extends AnyVal with Product with Serializable
-
case class
SourceInfo(filePath: String, fileName: String, offset: Int, line: Int, column: Int, lineContent: String, enclosingSymbols: List[String]) extends Product with Serializable
Macro-materialized implicit value that provides information about callsite source file position.
Macro-materialized implicit value that provides information about callsite source file position. It can be used in runtime for logging and debugging purposes. Similar to Scalactic's
Position
, but contains more information. -
final
class
Timestamp extends AnyVal with Comparable[Timestamp]
Millisecond-precision, general purpose, cross compiled timestamp representation.
- final class TimestampConversions extends AnyVal
-
final
class
TypeString[T] extends AnyVal
Typeclass that contains string representation of a concrete type.
Typeclass that contains string representation of a concrete type. This representation should correctly parse and typecheck when used as a type in Scala source code.
Instances of
TypeString
are implicitly macro-materialized. The macro will fail if the type contains references to local symbols, i.e. symbols that only exist in limited scope and cannot be referred to from any place in source code. This includes type parameters, this-references to enclosing classes, etc.For example, the code below will NOT compile:
def listTypeRepr[T]: String = TypeString.of[List[T]]
because
T
is a local symbol that only has meaning inside its own method. However, if you provide externalTypeString
instance forT
, the macro will pick it up and no longer complain:def listTypeRepr[T: TypeString]: String = TypeString.of[List[T]]
Then,
listTypeRepr[Int]
will produce a string"List[Int]"
-
abstract
class
TypedKey[T] extends AnyRef
Base class for sealed enums which can be used as key type for a TypedMap.
- trait TypedKeyCompanion[K[X] <: TypedKey[X]] extends SealedEnumCompanion[K[_]]
- final class TypedMap[K[_]] extends AnyVal
-
trait
Unapplier[T] extends AnyRef
Typeclass which captures case class
unapply
/unapplySeq
method in a raw form that returns untyped sequence of values.Typeclass which captures case class
unapply
/unapplySeq
method in a raw form that returns untyped sequence of values.- Annotations
- @implicitNotFound( ... )
- final case class Unboxing[+A, -B](fun: (B) ⇒ A) extends AnyVal with Product with Serializable
-
trait
ValueEnum extends NamedEnum
Base trait for
val
-based enums, i.e.Base trait for
val
-based enums, i.e. enums implemented as a single class with companion object keeping enum values as instances of the enum class infinal val
fields. This is an alternative way of implementing enums as compared to traditional Scala approach of using a sealed hierarchy with objects representing enum values.Advantages of value based enums over object based enums include:
- Much less classes generated, which in particular contributes to much less JavaScript output in ScalaJS. This may also speed up compilation.
- No need to explicitly implement
values
in enum's companion object as it is necessary when using SealedEnumCompanion and NamedEnumCompanion - It is possible to define all enum values in a single line of code (assuming they don't take parameters)
Disadvantages of value based enums over object based enums include:
- Every object can have its own separate public API, values cannot (although you can have a separate anonymous class for every value)
- Scala compiler does not perform exhaustive checking for pattern matching enum values - this is however
provided separately by
commons-analyzer
compiler plugin.
Enum classes must have a companion object which extends ValueEnumCompanion (prefer using AbstractValueEnumCompanion where possible). Every enum constant must be declared as a
final val
in the companion object and must have theValue
type explicitly ascribed (which is just a type alias for enum class itself). The enum class itself must take an implicit EnumCtx argument which provides information about enum ordinal and name as well as makes sure that enum value is registered in the companion object. If possible, you should always extend AbstractValueEnum instead of mixing in this trait. ValueEnum trait should only be mixed in directly when your enum class already has another superclass, incompatible with AbstractValueEnum.final class Weekday(implicit enumCtx: EnumCtx) extends AbstractValueEnum object Weekday extends AbstractValueEnumCompanion[Weekday] { final val Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday: Value = new Weekday }
Value based enums can take parameters:
final class Status(val description: String)(implicit enumCtx: EnumCtx) extends AbstractValueEnum object Status extends AbstractValueEnumCompanion[Status] { final val Enabled: Value = new Status("Something is enabled and working") final val Disabled: Value = new Status("Something is disabled and not working") }
Example: -
trait
ValueEnumCompanion[T <: ValueEnum] extends NamedEnumCompanion[T]
Base trait for companion objects of value based enums.
Base trait for companion objects of value based enums. See ValueEnum for more information. NOTE: if possible, prefer using AbstractValueEnumCompanion instead of this trait directly.
-
final
class
ValueOf[T] extends AnyVal
Macro materialized typeclass which captures the single value of a singleton type.
Macro materialized typeclass which captures the single value of a singleton type.
- Annotations
- @implicitNotFound( ... )
-
final
class
MacroGenerated[C, T] extends AnyVal
Wrapper class for macro-generated typeclasses.
Wrapper class for macro-generated typeclasses. Usually, a typeclass is wrapped in
MacroGenerated
when it's accepted as implicit super constructor parameter of some base class for companion objects of types for which the typeclass is being generated. Example: HasGenCodec, which is a base class for companion objects of classes that want GenCodec to be macro-generated for them.Instead of materializing the type class instance directly, a function from some base companion type
C
is materialized. To obtain the actual typeclass instance, companion object must be passed as this function's argument. This serves two purposes:- contents of
C
will be wildcard-imported into macro-materialization, allowing injection of additional implicits - working around too strict Scala validation of super constructor arguments: https://github.com/scala/bug/issues/7666- Annotations
- @deprecated
- Deprecated
(Since version 1.34) Use MacroInstances instead
Value Members
- object AnnotationOf extends Serializable
- object AnnotationsOf extends Serializable
- object Applier
- object ApplierUnapplier
-
object
Bidirectional
Creates reversed partial function.
- object Boxing extends LowPrioBoxing with Serializable
- object Bytes extends Serializable
- object CrossUtils
- object Delegation
- object HasAnnotation
- object ImplicitNotFound
- object Implicits
- object JavaClassName extends JavaClassNameLowPrio
- object MacroGenerated
- object NOpt extends Serializable
- object Opt extends Serializable
- object OptAnnotationOf extends Serializable
- object OptArg extends Serializable
- object OptRef extends Serializable
- object OrderedEnum
- object Sam
- object SamCompanion
- object SealedUtils
- object SelfAnnotation extends Serializable
- object SelfAnnotations extends Serializable
- object SelfInstance extends Serializable
- object SelfOptAnnotation extends Serializable
- object SimpleClassName extends Serializable
- object SourceInfo extends Serializable
- object Timestamp
- object TypeString
- object TypedMap
- object Unapplier
- object Unboxing extends LowPrioUnboxing with Serializable
- object ValueEnum extends Serializable
- object ValueOf