Class/Object

zio.prelude

Newtype

Related Docs: object Newtype | package prelude

Permalink

abstract class Newtype[A] extends NewtypeVersionSpecific

The class of objects corresponding to newtypes. Users should implement an object that extends this class to create their own newtypes, specifying A as the underlying type to wrap.

object Meter extends Newtype[Double]
type Meter = Meter.Type
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Newtype
  2. NewtypeVersionSpecific
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Newtype()

    Permalink

Type Members

  1. abstract type Base

    Permalink
    Definition Classes
    NewtypeVersionSpecific
  2. trait Tag extends Any

    Permalink
    Definition Classes
    NewtypeVersionSpecific
  3. type Type = Base with Tag

    Permalink
    Definition Classes
    NewtypeVersionSpecific
  4. type Wrapped = A

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. macro def apply(value: A, values: A*): NonEmptyChunk[Type]

    Permalink

    Converts multiple instances of the underlying type to NonEmptyChunk of instances of the newtype.

    Converts multiple instances of the underlying type to NonEmptyChunk of instances of the newtype.

    If there is a def assertion (see assert), each value will be checked at compile-time.

  5. macro def apply(value: A): Type

    Permalink

    Converts an instance of the underlying type to an instance of the newtype.

    Converts an instance of the underlying type to an instance of the newtype.

    If there is a def assertion (see assert), the value will be checked at compile-time.

  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. macro def assert(assertion: Assertion[A]): QuotedAssertion[A]

    Permalink

    This method is used to generate Newtype that can be validated at compile-time.

    This method is used to generate Newtype that can be validated at compile-time. This must wrap a Assertion and be assigned to def assertion.

    For example, here is a refined Newtype for Natural numbers. Natural numbers are whole numbers greater than or equal to 0.

    import zio.prelude.Subtype
    import zio.prelude.Assertion._
    
    type Natural = Natural.Type
    object Natural extends Subtype[Int] {
      def assertion = assert(greaterThanOrEqualTo(0))
    }

    With this assertion defined, Natural.apply will check literal values at compile-time, failing with an error message if the Assertion is not satisfied.

    Natural(-10) would render "-10 failed to satisfy greaterThanOrEqualTo(10)"

    IMPORTANT: Due to the macro machinery powering this feature, you must be sure to NOT ANNOTATE def assertion with a type (QuotedAssertion). If you do so, the macro will not be able to run the provided assertion at compile-time and will fail with a message containing this very same information.

  8. macro def assertCustom(f: (A) ⇒ Either[AssertionError, Unit]): QuotedAssertion[A]

    Permalink

    This method is used as an escape hatch for assert to allow Newtypes to use custom functions.

    This method is used as an escape hatch for assert to allow Newtypes to use custom functions. If at all possible, you should use assert instead.

    This will use whitebox.Context.eval under the hood, so all limitations of that function apply here. See here for details: https://github.com/scala/scala/blob/2.13.x/src/reflect/scala/reflect/macros/Evals.scala#L69

    IMPORTANT: Due to the macro machinery powering this feature, you must be sure to NOT ANNOTATE def assertion with a type (QuotedAssertion). If you do so, the macro will not be able to run the provided assertion at compile-time and will fail with a message containing this very same information.

  9. def assertion: QuotedAssertion[A]

    Permalink
  10. implicit def classTag(implicit underlying: ClassTag[A]): ClassTag[Type]

    Permalink
  11. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  12. def derive[TypeClass[_]](implicit instance: TypeClass[A]): TypeClass[Type]

    Permalink

    Derives an instance of a type class for the new type given an instance of the type class for the underlying type.

    Derives an instance of a type class for the new type given an instance of the type class for the underlying type. The caller is responsible for the type class being a valid instance for the new type.

    Attributes
    protected
  13. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  15. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  17. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  18. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  19. macro def make(value: A): Validation[String, Type]

    Permalink
  20. macro def makeAll[F[+_]](value: F[A])(implicit arg0: ForEach[F]): Validation[String, F[Type]]

    Permalink
  21. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  22. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  23. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  24. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  25. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  26. def unapply(value: Type): Some[A]

    Permalink

    Allows pattern matching on newtype instances to convert them back to instances of the underlying type.

  27. def unwrap(value: Type): A

    Permalink

    Converts an instance of the newtype back to an instance of the underlying type.

  28. def unwrapAll[F[_]](value: F[Type]): F[A]

    Permalink

    Converts an instance of a type parameterized on the newtype back to an instance of a type parameterized on the underlying type.

    Converts an instance of a type parameterized on the newtype back to an instance of a type parameterized on the underlying type. For example, this could be used to convert a list of instances of the newtype back to a list of instances of the underlying type.

  29. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. def wrap(value: A): Type

    Permalink

    Converts an instance of the underlying type to an instance of the newtype.

    Converts an instance of the underlying type to an instance of the newtype. Ignores the assertion.

    Attributes
    protected
  33. macro def wrapAll[F[_]](value: F[A]): F[Type]

    Permalink

    Converts an instance of a type parameterized on the underlying type to an instance of a type parameterized on the newtype.

    Converts an instance of a type parameterized on the underlying type to an instance of a type parameterized on the newtype. For example, this could be used to convert a list of instances of the underlying type to a list of instances of the newtype.

    Due to macro limitations, this method cannot with refined newtype and will thus issue a compiler error if you attempt to do so.

Inherited from NewtypeVersionSpecific

Inherited from AnyRef

Inherited from Any

Ungrouped