Packages

abstract class Newtype[Src] extends NewtypeTrait[Src]

Base class for defining newtypes that have no type parameters.

This class does not define any "builder", or related HasBuilder instance, as you're expected to provide one yourself.

Usage sample:

type EmailAddress = EmailAddress.Type

object EmailAddress extends Newtype[String] { self =>
  def apply(value: String): Option[Type] =
    if (value.contains("@"))
      Some(unsafeCoerce(value))
    else
      None

  // Recommended instance, but not required;
  // use Newtype.Validated to get rid of this boilerplate ;-)
  implicit val builder: HasBuilder.Aux[EmailAddress, String] =
    new HasBuilder[EmailAddress] {
      type Source = String

      def build(v: String): Either[BuildFailure[Type], Type] =
        apply(v) match {
          case Some(r) =>
            Right(r)
          case None =>
            Left(BuildFailure[EmailAddress]("missing @"))
        }
    }
}
Source
Newtype.scala
See also

NewtypeWrapped and NewtypeValidated for variants that provide an apply builder.

Newsubtype for defining _subtypes_ of the underlying type.

Linear Supertypes
NewtypeTrait[Src], NewEncoding[Src], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Newtype
  2. NewtypeTrait
  3. NewEncoding
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Newtype()

Type Members

  1. type Base = Any { type NewType$base }
    Definition Classes
    NewtypeTrait → NewEncoding
  2. implicit final class Ops extends AnyRef
    Definition Classes
    NewEncoding
  3. trait Tag extends Any
    Definition Classes
    NewEncoding
  4. abstract type Type <: Base with Tag
    Definition Classes
    NewEncoding

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  6. final def derive[F[_]](implicit ev: F[Src]): F[Type]
    Attributes
    protected
    Definition Classes
    NewEncoding
    Annotations
    @inline()
  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  9. final def extract(value: Type): Src
    Attributes
    protected
    Definition Classes
    NewEncoding
    Annotations
    @inline()
  10. implicit final val extractor: Aux[Type, Src]
    Definition Classes
    NewEncoding
  11. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  17. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. implicit val typeInfo: TypeInfo[Type]
    Definition Classes
    NewEncoding
  20. final def unsafeCoerce(value: Src): Type
    Attributes
    protected
    Definition Classes
    NewEncoding
    Annotations
    @inline()
  21. final def value(x: Type): Src
    Definition Classes
    NewEncoding
    Annotations
    @inline()
  22. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  23. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  24. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from NewtypeTrait[Src]

Inherited from NewEncoding[Src]

Inherited from AnyRef

Inherited from Any

Ungrouped