Package

com.avsystem.commons

misc

Permalink

package misc

Visibility
  1. Public
  2. All

Type Members

  1. abstract class AbstractCase extends CaseMethods

    Permalink
  2. abstract class AbstractNamedEnumCompanion[T <: NamedEnum] extends AbstractSealedEnumCompanion[T] with NamedEnumCompanion[T]

    Permalink
  3. abstract class AbstractSealedEnumCompanion[T] extends SealedEnumCompanion[T]

    Permalink
  4. abstract class AbstractValueEnum extends ValueEnum

    Permalink

    Convenience abstract class implementing ValueEnum.

    Convenience abstract class implementing ValueEnum. For less generated code, faster compilation and better binary compatibility it's better to extend this abstract class rather than ValueEnum trait directly. See ValueEnum documentation for more information on value-based enums.

  5. abstract class AbstractValueEnumCompanion[T <: ValueEnum] extends AbstractNamedEnumCompanion[T] with ValueEnumCompanion[T]

    Permalink

    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.

  6. final case class Boxing[-A, +B](fun: (A) ⇒ B) extends AnyVal with Product with Serializable

    Permalink
  7. trait CaseMethods extends Product

    Permalink

    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 and equals 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.

  8. trait Delegation[A, B] extends AnyRef

    Permalink

    A typeclass which witnesses that type A can be wrapped into trait or abstract class B

  9. sealed trait EnumCtx extends Any

    Permalink
    Annotations
    @implicitNotFound( ... )
  10. trait LowPrioBoxing extends AnyRef

    Permalink
  11. trait LowPrioUnboxing extends AnyRef

    Permalink
  12. final class NOpt[+A] extends AnyVal with Serializable

    Permalink

    Like Opt but does have a counterpart for Some(null).

    Like Opt but does have a counterpart for Some(null). In other words, NOpt is a "nullable Opt".

  13. trait NamedEnum extends Serializable

    Permalink

    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.

  14. trait NamedEnumCompanion[T <: NamedEnum] extends SealedEnumCompanion[T]

    Permalink

    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.byName

    Example:

    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.

  15. final class Opt[+A] extends AnyVal with Serializable

    Permalink

    Like Option but implemented as value class (avoids boxing) and treats null as no value.

    Like Option but implemented as value class (avoids boxing) and treats null as no value. Therefore, there is no equivalent for Some(null).

    If you need a value-class version of Option which differentiates between no value and null value, use NOpt.

  16. final class OptArg[+A] extends AnyVal with Serializable

    Permalink

    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 to OptArg[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 to OptArg[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 into OptArg.Empty.
    It is strongly recommended that OptArg type is used ONLY in signatures where implicit conversion A => OptArg[A] is intended to work. You should not use OptArg as a general-purpose "optional value" type - other types like Opt, NOpt and Option serve that purpose. For this reason OptArg deliberately does not have any "transforming" methods like map, flatMap, orElse, etc. Instead it's recommended that OptArg is converted to Opt, NOpt or Option as soon as possible (using toOpt, toNOpt and toOption methods).

  17. final class OptRef[+A >: Null] extends AnyVal with Serializable

    Permalink

    Like Opt but has better Java interop thanks to the fact that wrapped value has type A instead of Any.

    Like Opt but has better Java interop thanks to the fact that wrapped value has type A instead of Any. 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 using null which unfortunately makes OptRef suffer from SI-7396 (hashCode fails on OptRef.Empty which means that you can't add OptRef values into hash sets or use them as hash map keys).

  18. trait OrderedEnum extends AnyRef

    Permalink

    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 return First, Second and Third objects in exactly that order.

  19. abstract class SamCompanion[T, F] extends AnyRef

    Permalink
  20. trait SealedEnumCompanion[T] extends AnyRef

    Permalink

    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
    }
  21. case class SourceInfo(filePath: String, fileName: String, offset: Int, line: Int, column: Int, lineContent: String, enclosingSymbols: List[String]) extends Product with Serializable

    Permalink

    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.

  22. abstract class TypedKey[T] extends AnyRef

    Permalink

    Base class for sealed enums which can be used as key type for a TypedMap.

    Base class for sealed enums which can be used as key type for a TypedMap. It also ensures that the TypedMap using TypedKey as a key type will always have a GenCodec.

  23. trait TypedKeyCompanion[K[X] <: TypedKey[X]] extends SealedEnumCompanion[K[_]]

    Permalink
  24. final class TypedMap[K[_]] extends AnyVal

    Permalink
  25. final case class Unboxing[+A, -B](fun: (B) ⇒ A) extends AnyVal with Product with Serializable

    Permalink
  26. trait ValueEnum extends NamedEnum

    Permalink

    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 in final 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 the Value type explicitly ascribed. 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.

    Example:
    1. 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")
      }
  27. trait ValueEnumCompanion[T <: ValueEnum] extends NamedEnumCompanion[T]

    Permalink

    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.

Value Members

  1. object Bidirectional

    Permalink

    Creates reversed partial function.

  2. object Boxing extends LowPrioBoxing with Serializable

    Permalink
  3. object CrossUtils

    Permalink
  4. object Delegation

    Permalink
  5. object Implicits

    Permalink
  6. object NOpt extends Serializable

    Permalink
  7. object Opt extends Serializable

    Permalink
  8. object OptArg extends Serializable

    Permalink
  9. object OptRef extends Serializable

    Permalink
  10. object OrderedEnum

    Permalink
  11. object Sam

    Permalink
  12. object SamCompanion

    Permalink
  13. object SealedUtils

    Permalink
  14. object SourceInfo extends Serializable

    Permalink
  15. object TypedMap

    Permalink
  16. object Unboxing extends LowPrioUnboxing with Serializable

    Permalink
  17. object ValueEnum extends Serializable

    Permalink

Ungrouped