neotype

package neotype

Members list

Packages

package neotype.eval

Type members

Classlikes

trait IsSimpleType[A]

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object IsSimpleType

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
trait IsValidatedType[A]

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
abstract opaque class Newtype[A] extends TypeWrapper[A]

Newtype allows for the creation of distinct types from existing ones, enabling more type-safe code by leveraging the type system to enforce constraints at compile time.

Newtype allows for the creation of distinct types from existing ones, enabling more type-safe code by leveraging the type system to enforce constraints at compile time.

Overriding the validate method allows for custom validation logic to be executed at compile time, ensuring that the newtype is only created with valid input. If the validation fails, it will raise a compile-time error.

Example:

// DEFINITION
type Digits = Digits.Type
object Digits extends Newtype[String]:
 override inline def validate(value: String) =
   value.forall(_.isDigit)

// COMPILE-TIME VALIDATION
Digits("123") // Compiles successfully.
Digits("abc") // Would fail to compile due to validation.

// RUN-TIME VALIDATION
val input = "123"
Digits.make(input) // Right(Digits("123"))

val bad = "abc"
Digits.make(bad) // Left("String must be numeric")

Attributes

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

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Newtype.type
abstract opaque class Subtype[A] extends TypeWrapper[A]

Attributes

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

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Subtype.type
sealed abstract class TypeWrapper[A]

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Newtype[A]
class Subtype[A]

Extensions

Extensions

extension [A, B](value: B)(using newtype: WithType[A, B])
inline def unwrap: A

Unwraps the newtype, returning the underlying value.

Unwraps the newtype, returning the underlying value.

Attributes