PrimitiveType

zio.blocks.schema.PrimitiveType
See thePrimitiveType companion object
sealed trait PrimitiveType[A]

One of the scalar types that a Reflect.Primitive node stands for: Unit, Boolean, the numeric types, Char, String, the java.time types, java.util.Currency and java.util.UUID. Each case converts its type to and from DynamicValue and carries a Validation of its values.

Only DynamicSchema#check checks the validation: fromDynamicValue and Reflect#fromDynamicValue accept values that break it.

Attributes

See also
Companion
object
Source
PrimitiveType.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class BigDecimal
class BigInt
class Byte
class Double
class Float
class Int
class Long
class Short
class Boolean
class Char
class Currency
class DayOfWeek
class Duration
class Instant
class LocalDate
class LocalTime
class Month
class MonthDay
class OffsetTime
class Period
class String
class UUID
object Unit
class Year
class YearMonth
class ZoneId
class ZoneOffset
Show all

Members list

Value members

Abstract methods

def toDynamicValue(value: A): DynamicValue

Wraps value in a DynamicValue.Primitive of the matching PrimitiveValue case.

Wraps value in a DynamicValue.Primitive of the matching PrimitiveValue case.

Attributes

Source
PrimitiveType.scala
def typeId: TypeId[A]

Returns the type ID of A.

Returns the type ID of A.

Attributes

Source
PrimitiveType.scala

Returns the validation of the values of this type, Validation.None when there is none.

Returns the validation of the values of this type, Validation.None when there is none.

Attributes

Source
PrimitiveType.scala

Concrete methods

Returns the binding of a primitive node of this type.

Returns the binding of a primitive node of this type.

Attributes

Source
PrimitiveType.scala
def fromDynamicValue(value: DynamicValue): Either[SchemaError, A]

Converts value into an A, or returns an ExpectationMismatch error such as Expected Int. value must be a DynamicValue.Primitive. The numeric types and Char also accept a primitive value of one of the other numeric types or Char when converting it to this type and back gives the same value; every other type accepts only its own PrimitiveValue case. Because the JVM conversions saturate or wrap, a few lossy conversions pass that check: a Float or Double of 2^63 decodes as Long.MaxValue, a Float of 2^31 as Int.MaxValue, Int.MaxValue as the Float 2^31, Long.MaxValue as the Float or Double 2^63, a Char of 32768 or more as a negative Short (65408 or more as a negative Byte), and a negative Byte or Short as a Char of 65408 or 32768 or more (-1 as Char.MaxValue). The validation is not checked.

Converts value into an A, or returns an ExpectationMismatch error such as Expected Int. value must be a DynamicValue.Primitive. The numeric types and Char also accept a primitive value of one of the other numeric types or Char when converting it to this type and back gives the same value; every other type accepts only its own PrimitiveValue case. Because the JVM conversions saturate or wrap, a few lossy conversions pass that check: a Float or Double of 2^63 decodes as Long.MaxValue, a Float of 2^31 as Int.MaxValue, Int.MaxValue as the Float 2^31, Long.MaxValue as the Float or Double 2^63, a Char of 32768 or more as a negative Short (65408 or more as a negative Byte), and a negative Byte or Short as a Char of 65408 or 32768 or more (-1 as Char.MaxValue). The validation is not checked.

val year = PrimitiveType.Int(Validation.None)

val fromLong = year.fromDynamicValue(
 DynamicValue.Primitive(PrimitiveValue.Long(2021L))
) // Right(2021)
val fromDouble = year.fromDynamicValue(
 DynamicValue.Primitive(PrimitiveValue.Double(2021.5))
) // Left(zio.blocks.schema.SchemaError: Expected Int at: .)

Attributes

Source
PrimitiveType.scala