Subtype

neotype.Subtype
See theSubtype companion object
abstract opaque class Subtype[A] extends TypeWrapper[A]

Attributes

Companion
object
Graph
Supertypes
class TypeWrapper[A]
class Object
trait Matchable
class Any

Members list

Type members

Types

opaque type Type

Value members

Concrete methods

final def make(input: A): Either[String, Type]

Attempts to create a new instance of the Subtype for the given input by calling the validate method.

Attempts to create a new instance of the Subtype for the given input by calling the validate method.

If the validation fails, it will return a Left with an error message. If the validation succeeds, it will return a Right with the new instance.

Attributes

inline def unsafeMake(inline input: A): Type

WARNING! Creates a new instance of the newtype without performing any validation. ONLY USE THIS IF YOU KNOW WHAT YOU'RE DOING.

WARNING! Creates a new instance of the newtype without performing any validation. ONLY USE THIS IF YOU KNOW WHAT YOU'RE DOING.

This method should be used with caution, as it bypasses any validation defined in the validate method. It is recommended to use the apply method instead, which performs compile-time validation of the input.

Attributes

inline def unsafeMakeF[F[_]](inline input: F[A]): F[Type]

WARNING! This casts an F[A] to an F[Type] without performing any validation. ONLY USE THIS IF YOU KNOW WHAT YOU'RE DOING.

WARNING! This casts an F[A] to an F[Type] without performing any validation. ONLY USE THIS IF YOU KNOW WHAT YOU'RE DOING.

If, for instance, you have a List[A] and you want to convert it to a List[Type], you can use this method to do so.

Attributes

Inherited methods

inline def apply(inline input: A): Type

Creates a new instance of the newtype.

Creates a new instance of the newtype.

If the validate method is not defined for this, it will simply wrap the input in the neotype.

If validate is defined, it will be called at compile-time to check if the input is valid. If it fails, it will raise a compile-time error. input should be a literal or a constant expression, a compile-time known value—otherwise, you should use the make method instead.

Attributes

Inherited from:
TypeWrapper
inline def applyAll(inline values: A*): List[Type]

Creates a list of newtype instances.

Creates a list of newtype instances.

This will essentially call apply for each value in the list, performing the same compile-time validation for each element.

If any of the elements fail validation, it will raise a compile-time error. Otherwise, it will return a list of newtype instances.

Attributes

Inherited from:
TypeWrapper
def validate(input: A): Boolean | String

Validates the input and returns a boolean or an error message.

Validates the input and returns a boolean or an error message.

Attributes

Inherited from:
TypeWrapper

Givens

Givens

transparent inline given given_WithType_A_Type: WithType[A, Type]