Newtype

monix.newtypes.Newtype
abstract class Newtype[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 @"))
         }
     }
 }

Attributes

See also

NewtypeWrapped and NewtypeValidated for variants that provide an apply builder.

Newsubtype for defining subtypes of the underlying type.

Source
Newtype.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class NewtypeValidated[Src]
class NewtypeWrapped[Src]

Members list

Type members

Inherited and Abstract types

override opaque type Type

Attributes

Inherited from:
NewtypeTrait (hidden)
Source
NewEncoding.scala

Value members

Inherited methods

final inline protected def derive[F[_]](implicit ev: F[Src]): F[Type]

Attributes

Inherited from:
NewEncoding (hidden)
Source
NewEncoding.scala
final inline protected def unsafeCoerce(value: Src): Type

Attributes

Inherited from:
NewEncoding (hidden)
Source
NewEncoding.scala

Extensions

Inherited extensions

extension (self: Type)
final inline def value: Src

Attributes

Inherited from:
NewEncoding (hidden)
Source
NewEncoding.scala

Implicits

Inherited implicits

implicit val codec: Aux[Type, Src]

Attributes

Inherited from:
NewEncoding (hidden)
Source
NewEncoding.scala
implicit val typeInfo: TypeInfo[Type]

Attributes

Inherited from:
NewEncoding (hidden)
Source
NewEncoding.scala