Skip to main content

Pre-defined Types

Import

import refined4s.types.all.*

Refined Int

NegInt: negative Int

Compile-time Validation

NegInt(-1)
// res0: Type = -1
NegInt(0)
// error:
// Invalid value: [0]. It must be a negative Int
NegInt(1)
// error:
// Invalid value: [1]. It must be a negative Int

Runtime Validation

val validNegInt = -1 
// validNegInt: Int = -1
NegInt.from(validNegInt)
// res3: Either[String, Type] = Right(value = -1)
val invalidNegInt1 = 0 
// invalidNegInt1: Int = 0
NegInt.from(invalidNegInt1)
// res4: Either[String, Type] = Left(
// value = "Invalid value: [0]. It must be a negative Int"
// )

val invalidNegInt2 = 1
// invalidNegInt2: Int = 1
NegInt.from(invalidNegInt2)
// res5: Either[String, Type] = Left(
// value = "Invalid value: [1]. It must be a negative Int"
// )

Comparison

val negInt1 = NegInt(-1)
// negInt1: Type = -1
val negInt2 = NegInt(-2)
// negInt2: Type = -2

negInt1 > negInt2
// res6: Boolean = true
negInt1 >= negInt2
// res7: Boolean = true
negInt1 == negInt2
// res8: Boolean = false
negInt1 < negInt2
// res9: Boolean = false
negInt1 <= negInt2
// res10: Boolean = false

Get Value

val negInt123 = NegInt(-123)
// negInt123: Type = -123
val negInt999 = NegInt(-999)
// negInt999: Type = -999

negInt123.value
// res11: Int = -123

negInt999.value
// res12: Int = -999

Min and Max Values

NegInt.MinValue
// res13: Type = -2147483648

NegInt.MaxValue
// res14: Type = -1

NonNegInt: non-negative Int

Compile-time Validation

NonNegInt(0)
// res15: Type = 0
NonNegInt(1)
// res16: Type = 1
NonNegInt(-2)
// error:
// Invalid value: [-2]. It must be a non-negative Int

Runtime Validation

val validNonNegInt = 1 
// validNonNegInt: Int = 1
NonNegInt.from(validNonNegInt)
// res17: Either[String, Type] = Right(value = 1)
val invalidNonNegInt1 = -1
// invalidNonNegInt1: Int = -1
NonNegInt.from(invalidNonNegInt1)
// res18: Either[String, Type] = Left(
// value = "Invalid value: [-1]. It must be a non-negative Int"
// )

val invalidNonNegInt2 = -999
// invalidNonNegInt2: Int = -999
NonNegInt.from(invalidNonNegInt2)
// res19: Either[String, Type] = Left(
// value = "Invalid value: [-999]. It must be a non-negative Int"
// )

Comparison

val nonNegInt1 = NonNegInt(0)
// nonNegInt1: Type = 0
val nonNegInt2 = NonNegInt(999)
// nonNegInt2: Type = 999

nonNegInt1 > nonNegInt2
// res20: Boolean = false
nonNegInt1 >= nonNegInt2
// res21: Boolean = false
nonNegInt1 == nonNegInt2
// res22: Boolean = false
nonNegInt1 < nonNegInt2
// res23: Boolean = true
nonNegInt1 <= nonNegInt2
// res24: Boolean = true

Get Value

val nonNegInt123 = NonNegInt(0)
// nonNegInt123: Type = 0
val nonNegInt999 = NonNegInt(999)
// nonNegInt999: Type = 999

nonNegInt123.value
// res25: Int = 0

nonNegInt999.value
// res26: Int = 999

Min and Max Values

NonNegInt.MinValue
// res27: Type = 0

NonNegInt.MaxValue
// res28: Type = 2147483647

PosInt: positive Int

Compile-time Validation

PosInt(1)
// res29: Type = 1
PosInt(999)
// res30: Type = 999
PosInt(0)
// error:
// Invalid value: [0]. It must be a positive Int
PosInt(-2)
// error:
// Invalid value: [-2]. It must be a positive Int

Runtime Validation

val validPosInt = 1
// validPosInt: Int = 1
PosInt.from(validPosInt)
// res31: Either[String, Type] = Right(value = 1)
val invalidPosInt1 = 0
// invalidPosInt1: Int = 0
PosInt.from(invalidPosInt1)
// res32: Either[String, Type] = Left(
// value = "Invalid value: [0]. It must be a positive Int"
// )

val invalidPosInt2 = -999
// invalidPosInt2: Int = -999
PosInt.from(invalidPosInt2)
// res33: Either[String, Type] = Left(
// value = "Invalid value: [-999]. It must be a positive Int"
// )

Comparison

val posInt1 = PosInt(1)
// posInt1: Type = 1
val posInt2 = PosInt(999)
// posInt2: Type = 999

posInt1 > posInt2
// res34: Boolean = false
posInt1 >= posInt2
// res35: Boolean = false
posInt1 == posInt2
// res36: Boolean = false
posInt1 < posInt2
// res37: Boolean = true
posInt1 <= posInt2
// res38: Boolean = true

Get Value

val posInt123 = PosInt(123)
// posInt123: Type = 123
val posInt999 = PosInt(999)
// posInt999: Type = 999

posInt123.value
// res39: Int = 123

posInt999.value
// res40: Int = 999

Min and Max Values

PosInt.MinValue
// res41: Type = 1

PosInt.MaxValue
// res42: Type = 2147483647

NonPosInt: non-positive Int

Compile-time Validation

NonPosInt(0)
// res43: Type = 0
NonPosInt(-999)
// res44: Type = -999
NonPosInt(1)
// error:
// Invalid value: [1]. It must be a non-positive Int

Runtime Validation

val validNonPosInt = 0
// validNonPosInt: Int = 0
NonPosInt.from(validNonPosInt)
// res45: Either[String, Type] = Right(value = 0)

val validNonPosInt2 = -999
// validNonPosInt2: Int = -999
NonPosInt.from(validNonPosInt2)
// res46: Either[String, Type] = Right(value = -999)
val invalidNonPosInt1 = 1
// invalidNonPosInt1: Int = 1
NonPosInt.from(invalidNonPosInt1)
// res47: Either[String, Type] = Left(
// value = "Invalid value: [1]. It must be a non-positive Int"
// )

val invalidNonPosInt2 = 999
// invalidNonPosInt2: Int = 999
NonPosInt.from(invalidNonPosInt2)
// res48: Either[String, Type] = Left(
// value = "Invalid value: [999]. It must be a non-positive Int"
// )

Comparison

val nonPosInt1 = NonPosInt(0)
// nonPosInt1: Type = 0
val nonPosInt2 = NonPosInt(-999)
// nonPosInt2: Type = -999

nonPosInt1 > nonPosInt2
// res49: Boolean = true
nonPosInt1 >= nonPosInt2
// res50: Boolean = true
nonPosInt1 == nonPosInt2
// res51: Boolean = false
nonPosInt1 < nonPosInt2
// res52: Boolean = false
nonPosInt1 <= nonPosInt2
// res53: Boolean = false

Get Value

val nonPosInt0 = NonPosInt(0)
// nonPosInt0: Type = 0
val nonPosIntMinus999 = NonPosInt(-999)
// nonPosIntMinus999: Type = -999

nonPosInt0.value
// res54: Int = 0

nonPosIntMinus999.value
// res55: Int = -999

Min and Max Values

NonPosInt.MinValue
// res56: Type = -2147483648

NonPosInt.MaxValue
// res57: Type = 0

Refined Long

NegLong: negative Long

Compile-time Validation

NegLong(-1L)
// res58: Type = -1L
NegLong(0L)
// error:
// Invalid value: [0L]. It must be a negative Long
NegLong(1L)
// error:
// Invalid value: [1L]. It must be a negative Long

Runtime Validation

val validNegLong = -1L 
// validNegLong: Long = -1L
NegLong.from(validNegLong)
// res59: Either[String, Type] = Right(value = -1L)
val invalidNegLong1 = 0L 
// invalidNegLong1: Long = 0L
NegLong.from(invalidNegLong1)
// res60: Either[String, Type] = Left(
// value = "Invalid value: [0]. It must be a negative Long"
// )

val invalidNegLong2 = 1L
// invalidNegLong2: Long = 1L
NegLong.from(invalidNegLong2)
// res61: Either[String, Type] = Left(
// value = "Invalid value: [1]. It must be a negative Long"
// )

Comparison

val negLong1 = NegLong(-1L)
// negLong1: Type = -1L
val negLong2 = NegLong(-2L)
// negLong2: Type = -2L

negLong1 > negLong2
// res62: Boolean = true
negLong1 >= negLong2
// res63: Boolean = true
negLong1 == negLong2
// res64: Boolean = false
negLong1 < negLong2
// res65: Boolean = false
negLong1 <= negLong2
// res66: Boolean = false

Get Value

val negLong123 = NegLong(-123L)
// negLong123: Type = -123L
val negLong999 = NegLong(-999L)
// negLong999: Type = -999L

negLong123.value
// res67: Long = -123L

negLong999.value
// res68: Long = -999L

Min and Max Values

NegLong.MinValue
// res69: Type = -9223372036854775808L

NegLong.MaxValue
// res70: Type = -1L

NonNegLong: non-negative Long

Compile-time Validation

NonNegLong(0L)
// res71: Type = 0L
NonNegLong(1L)
// res72: Type = 1L
NonNegLong(-2L)
// error:
// Invalid value: [-2L]. It must be a non-negative Long

Runtime Validation

val validNonNegLong = 1L
// validNonNegLong: Long = 1L
NonNegLong.from(validNonNegLong)
// res73: Either[String, Type] = Right(value = 1L)
val invalidNonNegLong1 = -1L
// invalidNonNegLong1: Long = -1L
NonNegLong.from(invalidNonNegLong1)
// res74: Either[String, Type] = Left(
// value = "Invalid value: [-1]. It must be a non-negative Long"
// )

val invalidNonNegLong2 = -999L
// invalidNonNegLong2: Long = -999L
NonNegLong.from(invalidNonNegLong2)
// res75: Either[String, Type] = Left(
// value = "Invalid value: [-999]. It must be a non-negative Long"
// )

Comparison

val nonNegLong1 = NonNegLong(0L)
// nonNegLong1: Type = 0L
val nonNegLong2 = NonNegLong(999L)
// nonNegLong2: Type = 999L

nonNegLong1 > nonNegLong2
// res76: Boolean = false
nonNegLong1 >= nonNegLong2
// res77: Boolean = false
nonNegLong1 == nonNegLong2
// res78: Boolean = false
nonNegLong1 < nonNegLong2
// res79: Boolean = true
nonNegLong1 <= nonNegLong2
// res80: Boolean = true

Get Value

val nonNegLong123 = NonNegLong(0L)
// nonNegLong123: Type = 0L
val nonNegLong999 = NonNegLong(999L)
// nonNegLong999: Type = 999L

nonNegLong123.value
// res81: Long = 0L

nonNegLong999.value
// res82: Long = 999L

Min and Max Values

NonNegLong.MinValue
// res83: Type = 0L

NonNegLong.MaxValue
// res84: Type = 9223372036854775807L

PosLong: positive Long

Compile-time Validation

PosLong(1L)
// res85: Type = 1L
PosLong(999L)
// res86: Type = 999L
PosLong(0L)
// error:
// Invalid value: [0L]. It must be a positive Long
PosLong(-2L)
// error:
// Invalid value: [-2L]. It must be a positive Long

Runtime Validation

val validPosLong = 1L
// validPosLong: Long = 1L
PosLong.from(validPosLong)
// res87: Either[String, Type] = Right(value = 1L)
val invalidPosLong1 = 0L
// invalidPosLong1: Long = 0L
PosLong.from(invalidPosLong1)
// res88: Either[String, Type] = Left(
// value = "Invalid value: [0]. It must be a positive Long"
// )

val invalidPosLong2 = -999L
// invalidPosLong2: Long = -999L
PosLong.from(invalidPosLong2)
// res89: Either[String, Type] = Left(
// value = "Invalid value: [-999]. It must be a positive Long"
// )

Comparison

val posLong1 = PosLong(1L)
// posLong1: Type = 1L
val posLong2 = PosLong(999L)
// posLong2: Type = 999L

posLong1 > posLong2
// res90: Boolean = false
posLong1 >= posLong2
// res91: Boolean = false
posLong1 == posLong2
// res92: Boolean = false
posLong1 < posLong2
// res93: Boolean = true
posLong1 <= posLong2
// res94: Boolean = true

Get Value

val posLong123 = PosLong(123L)
// posLong123: Type = 123L
val posLong999 = PosLong(999L)
// posLong999: Type = 999L

posLong123.value
// res95: Long = 123L

posLong999.value
// res96: Long = 999L

Min and Max Values

PosLong.MinValue
// res97: Type = 1L

PosLong.MaxValue
// res98: Type = 9223372036854775807L

NonPosLong: non-positive Long

Compile-time Validation

NonPosLong(0L)
// res99: Type = 0L
NonPosLong(-999L)
// res100: Type = -999L
NonPosLong(1L)
// error:
// Invalid value: [1L]. It must be a non-positive Long

Runtime Validation

val validNonPosLong = 0L
// validNonPosLong: Long = 0L
NonPosLong.from(validNonPosLong)
// res101: Either[String, Type] = Right(value = 0L)

val validNonPosLong2 = -999L
// validNonPosLong2: Long = -999L
NonPosLong.from(validNonPosLong2)
// res102: Either[String, Type] = Right(value = -999L)
val invalidNonPosLong1 = 1L
// invalidNonPosLong1: Long = 1L
NonPosLong.from(invalidNonPosLong1)
// res103: Either[String, Type] = Left(
// value = "Invalid value: [1]. It must be a non-positive Long"
// )

val invalidNonPosLong2 = 999L
// invalidNonPosLong2: Long = 999L
NonPosLong.from(invalidNonPosLong2)
// res104: Either[String, Type] = Left(
// value = "Invalid value: [999]. It must be a non-positive Long"
// )

Comparison

val nonPosLong1 = NonPosLong(0L)
// nonPosLong1: Type = 0L
val nonPosLong2 = NonPosLong(-999L)
// nonPosLong2: Type = -999L

nonPosLong1 > nonPosLong2
// res105: Boolean = true
nonPosLong1 >= nonPosLong2
// res106: Boolean = true
nonPosLong1 == nonPosLong2
// res107: Boolean = false
nonPosLong1 < nonPosLong2
// res108: Boolean = false
nonPosLong1 <= nonPosLong2
// res109: Boolean = false

Get Value

val nonPosLong0 = NonPosLong(0L)
// nonPosLong0: Type = 0L
val nonPosLongMinus999 = NonPosLong(-999L)
// nonPosLongMinus999: Type = -999L

nonPosLong0.value
// res110: Long = 0L

nonPosLongMinus999.value
// res111: Long = -999L

Min and Max Values

NonPosLong.MinValue
// res112: Type = -9223372036854775808L

NonPosLong.MaxValue
// res113: Type = 0L

Refined Double

NegDouble: negative Double

Compile-time Validation

NegDouble(-0.00001d)
// res114: Type = -1.0E-5
NegDouble(-999.999d)
// res115: Type = -999.999
NegDouble(0d)
// error:
// Invalid value: [0.0d]. It must be a negative Double
NegDouble(999.999d)
// error:
// Invalid value: [999.999d]. It must be a negative Double

Runtime Validation

val validNegDouble = -0.00001d 
// validNegDouble: Double = -1.0E-5
NegDouble.from(validNegDouble)
// res116: Either[String, Type] = Right(value = -1.0E-5)
val invalidNegDouble1 = 0d 
// invalidNegDouble1: Double = 0.0
NegDouble.from(invalidNegDouble1)
// res117: Either[String, Type] = Left(
// value = "Invalid value: [0.0]. It must be a negative Double"
// )

val invalidNegDouble2 = 999.999d
// invalidNegDouble2: Double = 999.999
NegDouble.from(invalidNegDouble2)
// res118: Either[String, Type] = Left(
// value = "Invalid value: [999.999]. It must be a negative Double"
// )

Comparison

val negDouble1 = NegDouble(-0.1d)
// negDouble1: Type = -0.1
val negDouble2 = NegDouble(-0.2d)
// negDouble2: Type = -0.2

negDouble1 > negDouble2
// res119: Boolean = true
negDouble1 >= negDouble2
// res120: Boolean = true
negDouble1 == negDouble2
// res121: Boolean = false
negDouble1 < negDouble2
// res122: Boolean = false
negDouble1 <= negDouble2
// res123: Boolean = false

Get Value

val negDouble123 = NegDouble(-123.123d)
// negDouble123: Type = -123.123
val negDouble999 = NegDouble(-999.999d)
// negDouble999: Type = -999.999

negDouble123.value
// res124: Double = -123.123

negDouble999.value
// res125: Double = -999.999

Min and Max Values

NegDouble.MinValue
// res126: Type = -1.7976931348623157E308

NegDouble.MaxValue
// res127: Type = -4.9E-324

NonNegDouble: non-negative Double

Compile-time Validation

NonNegDouble(0d)
// res128: Type = 0.0
NonNegDouble(999.999d)
// res129: Type = 999.999
NonNegDouble(-0.00001d)
// error:
// Invalid value: [-1.0E-5d]. It must be a non-negative Double
NonNegDouble(-999.999d)
// error:
// Invalid value: [-999.999d]. It must be a non-negative Double

Runtime Validation

val validNonNegDouble1 = 0d
// validNonNegDouble1: Double = 0.0
NonNegDouble.from(validNonNegDouble1)
// res130: Either[String, Type] = Right(value = 0.0)

val validNonNegDouble2 = 999.999d
// validNonNegDouble2: Double = 999.999
NonNegDouble.from(validNonNegDouble2)
// res131: Either[String, Type] = Right(value = 999.999)
val invalidNonNegDouble1 = -0.00001d
// invalidNonNegDouble1: Double = -1.0E-5
NonNegDouble.from(invalidNonNegDouble1)
// res132: Either[String, Type] = Left(
// value = "Invalid value: [-1.0E-5]. It must be a non-negative Double"
// )

val invalidNonNegDouble2 = -999.999d
// invalidNonNegDouble2: Double = -999.999
NonNegDouble.from(invalidNonNegDouble2)
// res133: Either[String, Type] = Left(
// value = "Invalid value: [-999.999]. It must be a non-negative Double"
// )

Comparison

val nonNegDouble1 = NonNegDouble(0d)
// nonNegDouble1: Type = 0.0
val nonNegDouble2 = NonNegDouble(0.999d)
// nonNegDouble2: Type = 0.999

nonNegDouble1 > nonNegDouble2
// res134: Boolean = false
nonNegDouble1 >= nonNegDouble2
// res135: Boolean = false
nonNegDouble1 == nonNegDouble2
// res136: Boolean = false
nonNegDouble1 < nonNegDouble2
// res137: Boolean = true
nonNegDouble1 <= nonNegDouble2
// res138: Boolean = true

Get Value

val nonNegDouble123 = NonNegDouble(0d)
// nonNegDouble123: Type = 0.0
val nonNegDouble999 = NonNegDouble(999.999d)
// nonNegDouble999: Type = 999.999

nonNegDouble123.value
// res139: Double = 0.0

nonNegDouble999.value
// res140: Double = 999.999

Min and Max Values

NonNegDouble.MinValue
// res141: Type = 0.0

NonNegDouble.MaxValue
// res142: Type = 1.7976931348623157E308

PosDouble: positive Double

Compile-time Validation

PosDouble(0.00001d)
// res143: Type = 1.0E-5
PosDouble(999.999d)
// res144: Type = 999.999
PosDouble(0d)
// error:
// Invalid value: [0.0d]. It must be a positive Double
PosDouble(-999.999d)
// error:
// Invalid value: [-999.999d]. It must be a positive Double

Runtime Validation

val validPosDouble1 = 0.00001d
// validPosDouble1: Double = 1.0E-5
PosDouble.from(validPosDouble1)
// res145: Either[String, Type] = Right(value = 1.0E-5)

val validPosDouble2 = 999.999d
// validPosDouble2: Double = 999.999
PosDouble.from(validPosDouble2)
// res146: Either[String, Type] = Right(value = 999.999)
val invalidPosDouble1 = 0d
// invalidPosDouble1: Double = 0.0
PosDouble.from(invalidPosDouble1)
// res147: Either[String, Type] = Left(
// value = "Invalid value: [0.0]. It must be a positive Double"
// )

val invalidPosDouble2 = -999.999d
// invalidPosDouble2: Double = -999.999
PosDouble.from(invalidPosDouble2)
// res148: Either[String, Type] = Left(
// value = "Invalid value: [-999.999]. It must be a positive Double"
// )

Comparison

val posDouble1 = PosDouble(0.00001d)
// posDouble1: Type = 1.0E-5
val posDouble2 = PosDouble(0.999d)
// posDouble2: Type = 0.999

posDouble1 > posDouble2
// res149: Boolean = false
posDouble1 >= posDouble2
// res150: Boolean = false
posDouble1 == posDouble2
// res151: Boolean = false
posDouble1 < posDouble2
// res152: Boolean = true
posDouble1 <= posDouble2
// res153: Boolean = true

Get Value

val posDouble123 = PosDouble(123.123d)
// posDouble123: Type = 123.123
val posDouble999 = PosDouble(999.999d)
// posDouble999: Type = 999.999

posDouble123.value
// res154: Double = 123.123

posDouble999.value
// res155: Double = 999.999

Min and Max Values

PosDouble.MinValue
// res156: Type = 4.9E-324

PosDouble.MaxValue
// res157: Type = 1.7976931348623157E308

NonPosDouble: non-positive Double

Compile-time Validation

NonPosDouble(0d)
// res158: Type = 0.0
NonPosDouble(-999.999d)
// res159: Type = -999.999
NonPosDouble(0.00001d)
// error:
// Invalid value: [1.0E-5d]. It must be a non-positive Double
NonPosDouble(999.999d)
// error:
// Invalid value: [999.999d]. It must be a non-positive Double

Runtime Validation

val validNonPosDouble = 0d
// validNonPosDouble: Double = 0.0
NonPosDouble.from(validNonPosDouble)
// res160: Either[String, Type] = Right(value = 0.0)

val validNonPosDouble2 = -999.999d
// validNonPosDouble2: Double = -999.999
NonPosDouble.from(validNonPosDouble2)
// res161: Either[String, Type] = Right(value = -999.999)
val invalidNonPosDouble1 = 0.00001d
// invalidNonPosDouble1: Double = 1.0E-5
NonPosDouble.from(invalidNonPosDouble1)
// res162: Either[String, Type] = Left(
// value = "Invalid value: [1.0E-5]. It must be a non-positive Double"
// )

val invalidNonPosDouble2 = 999.999d
// invalidNonPosDouble2: Double = 999.999
NonPosDouble.from(invalidNonPosDouble2)
// res163: Either[String, Type] = Left(
// value = "Invalid value: [999.999]. It must be a non-positive Double"
// )

Comparison

val nonPosDouble1 = NonPosDouble(0d)
// nonPosDouble1: Type = 0.0
val nonPosDouble2 = NonPosDouble(-0.999d)
// nonPosDouble2: Type = -0.999

nonPosDouble1 > nonPosDouble2
// res164: Boolean = true
nonPosDouble1 >= nonPosDouble2
// res165: Boolean = true
nonPosDouble1 == nonPosDouble2
// res166: Boolean = false
nonPosDouble1 < nonPosDouble2
// res167: Boolean = false
nonPosDouble1 <= nonPosDouble2
// res168: Boolean = false

Get Value

val nonPosDouble0 = NonPosDouble(0d)
// nonPosDouble0: Type = 0.0
val nonPosDoubleMinus999 = NonPosDouble(-999.999d)
// nonPosDoubleMinus999: Type = -999.999

nonPosDouble0.value
// res169: Double = 0.0

nonPosDoubleMinus999.value
// res170: Double = -999.999

Min and Max Values

NonPosDouble.MinValue
// res171: Type = -1.7976931348623157E308

NonPosDouble.MaxValue
// res172: Type = 0.0

Refined Float

NegFloat: negative Float

Compile-time Validation

NegFloat(-0.00001f)
// res173: Type = -1.0E-5F
NegFloat(-999.999f)
// res174: Type = -999.999F
NegFloat(0f)
// error:
// Invalid value: [0.0f]. It must be a negative Float
NegFloat(999.999f)
// error:
// Invalid value: [999.999f]. It must be a negative Float

Runtime Validation

val validNegFloat = -0.00001f 
// validNegFloat: Float = -1.0E-5F
NegFloat.from(validNegFloat)
// res175: Either[String, Type] = Right(value = -1.0E-5F)
val invalidNegFloat1 = 0f 
// invalidNegFloat1: Float = 0.0F
NegFloat.from(invalidNegFloat1)
// res176: Either[String, Type] = Left(
// value = "Invalid value: [0.0]. It must be a negative Float"
// )

val invalidNegFloat2 = 999.999f
// invalidNegFloat2: Float = 999.999F
NegFloat.from(invalidNegFloat2)
// res177: Either[String, Type] = Left(
// value = "Invalid value: [999.999]. It must be a negative Float"
// )

Comparison

val negFloat1 = NegFloat(-0.1f)
// negFloat1: Type = -0.1F
val negFloat2 = NegFloat(-0.2f)
// negFloat2: Type = -0.2F

negFloat1 > negFloat2
// res178: Boolean = true
negFloat1 >= negFloat2
// res179: Boolean = true
negFloat1 == negFloat2
// res180: Boolean = false
negFloat1 < negFloat2
// res181: Boolean = false
negFloat1 <= negFloat2
// res182: Boolean = false

Get Value

val negFloat123 = NegFloat(-123.123f)
// negFloat123: Type = -123.123F
val negFloat999 = NegFloat(-999.999f)
// negFloat999: Type = -999.999F

negFloat123.value
// res183: Float = -123.123F

negFloat999.value
// res184: Float = -999.999F

Min and Max Values

NegFloat.MinValue
// res185: Type = -3.4028235E38F

NegFloat.MaxValue
// res186: Type = -1.4E-45F

NonNegFloat: non-negative Float

Compile-time Validation

NonNegFloat(0f)
// res187: Type = 0.0F
NonNegFloat(999.999f)
// res188: Type = 999.999F
NonNegFloat(-0.00001f)
// error:
// Invalid value: [-1.0E-5f]. It must be a non-negative Float
NonNegFloat(-999.999f)
// error:
// Invalid value: [-999.999f]. It must be a non-negative Float

Runtime Validation

val validNonNegFloat1 = 0f
// validNonNegFloat1: Float = 0.0F
NonNegFloat.from(validNonNegFloat1)
// res189: Either[String, Type] = Right(value = 0.0F)

val validNonNegFloat2 = 999.999f
// validNonNegFloat2: Float = 999.999F
NonNegFloat.from(validNonNegFloat2)
// res190: Either[String, Type] = Right(value = 999.999F)
val invalidNonNegFloat1 = -0.00001f
// invalidNonNegFloat1: Float = -1.0E-5F
NonNegFloat.from(invalidNonNegFloat1)
// res191: Either[String, Type] = Left(
// value = "Invalid value: [-1.0E-5]. It must be a non-negative Float"
// )

val invalidNonNegFloat2 = -999.999f
// invalidNonNegFloat2: Float = -999.999F
NonNegFloat.from(invalidNonNegFloat2)
// res192: Either[String, Type] = Left(
// value = "Invalid value: [-999.999]. It must be a non-negative Float"
// )

Comparison

val nonNegFloat1 = NonNegFloat(0f)
// nonNegFloat1: Type = 0.0F
val nonNegFloat2 = NonNegFloat(0.999f)
// nonNegFloat2: Type = 0.999F

nonNegFloat1 > nonNegFloat2
// res193: Boolean = false
nonNegFloat1 >= nonNegFloat2
// res194: Boolean = false
nonNegFloat1 == nonNegFloat2
// res195: Boolean = false
nonNegFloat1 < nonNegFloat2
// res196: Boolean = true
nonNegFloat1 <= nonNegFloat2
// res197: Boolean = true

Get Value

val nonNegFloat123 = NonNegFloat(0f)
// nonNegFloat123: Type = 0.0F
val nonNegFloat999 = NonNegFloat(999.999f)
// nonNegFloat999: Type = 999.999F

nonNegFloat123.value
// res198: Float = 0.0F

nonNegFloat999.value
// res199: Float = 999.999F

Min and Max Values

NonNegFloat.MinValue
// res200: Type = 0.0F

NonNegFloat.MaxValue
// res201: Type = 3.4028235E38F

PosFloat: positive Float

Compile-time Validation

PosFloat(0.00001f)
// res202: Type = 1.0E-5F
PosFloat(999.999f)
// res203: Type = 999.999F
PosFloat(0f)
// error:
// Invalid value: [0.0f]. It must be a positive Float
PosFloat(-999.999f)
// error:
// Invalid value: [-999.999f]. It must be a positive Float

Runtime Validation

val validPosFloat1 = 0.00001f
// validPosFloat1: Float = 1.0E-5F
PosFloat.from(validPosFloat1)
// res204: Either[String, Type] = Right(value = 1.0E-5F)

val validPosFloat2 = 999.999f
// validPosFloat2: Float = 999.999F
PosFloat.from(validPosFloat2)
// res205: Either[String, Type] = Right(value = 999.999F)
val invalidPosFloat1 = 0f
// invalidPosFloat1: Float = 0.0F
PosFloat.from(invalidPosFloat1)
// res206: Either[String, Type] = Left(
// value = "Invalid value: [0.0]. It must be a positive Float"
// )

val invalidPosFloat2 = -999.999f
// invalidPosFloat2: Float = -999.999F
PosFloat.from(invalidPosFloat2)
// res207: Either[String, Type] = Left(
// value = "Invalid value: [-999.999]. It must be a positive Float"
// )

Comparison

val posFloat1 = PosFloat(0.00001f)
// posFloat1: Type = 1.0E-5F
val posFloat2 = PosFloat(0.999f)
// posFloat2: Type = 0.999F

posFloat1 > posFloat2
// res208: Boolean = false
posFloat1 >= posFloat2
// res209: Boolean = false
posFloat1 == posFloat2
// res210: Boolean = false
posFloat1 < posFloat2
// res211: Boolean = true
posFloat1 <= posFloat2
// res212: Boolean = true

Get Value

val posFloat123 = PosFloat(123.123f)
// posFloat123: Type = 123.123F
val posFloat999 = PosFloat(999.999f)
// posFloat999: Type = 999.999F

posFloat123.value
// res213: Float = 123.123F

posFloat999.value
// res214: Float = 999.999F

Min and Max Values

PosFloat.MinValue
// res215: Type = 1.4E-45F

PosFloat.MaxValue
// res216: Type = 3.4028235E38F

NonPosFloat: non-positive Float

Compile-time Validation

NonPosFloat(0f)
// res217: Type = 0.0F
NonPosFloat(-999.999f)
// res218: Type = -999.999F
NonPosFloat(0.00001f)
// error:
// Invalid value: [1.0E-5f]. It must be a non-positive Float
NonPosFloat(999.999f)
// error:
// Invalid value: [999.999f]. It must be a non-positive Float

Runtime Validation

val validNonPosFloat = 0f
// validNonPosFloat: Float = 0.0F
NonPosFloat.from(validNonPosFloat)
// res219: Either[String, Type] = Right(value = 0.0F)

val validNonPosFloat2 = -999.999f
// validNonPosFloat2: Float = -999.999F
NonPosFloat.from(validNonPosFloat2)
// res220: Either[String, Type] = Right(value = -999.999F)
val invalidNonPosFloat1 = 0.00001f
// invalidNonPosFloat1: Float = 1.0E-5F
NonPosFloat.from(invalidNonPosFloat1)
// res221: Either[String, Type] = Left(
// value = "Invalid value: [1.0E-5]. It must be a non-positive Float"
// )

val invalidNonPosFloat2 = 999.999f
// invalidNonPosFloat2: Float = 999.999F
NonPosFloat.from(invalidNonPosFloat2)
// res222: Either[String, Type] = Left(
// value = "Invalid value: [999.999]. It must be a non-positive Float"
// )

Comparison

val nonPosFloat1 = NonPosFloat(0f)
// nonPosFloat1: Type = 0.0F
val nonPosFloat2 = NonPosFloat(-0.999f)
// nonPosFloat2: Type = -0.999F

nonPosFloat1 > nonPosFloat2
// res223: Boolean = true
nonPosFloat1 >= nonPosFloat2
// res224: Boolean = true
nonPosFloat1 == nonPosFloat2
// res225: Boolean = false
nonPosFloat1 < nonPosFloat2
// res226: Boolean = false
nonPosFloat1 <= nonPosFloat2
// res227: Boolean = false

Get Value

val nonPosFloat0 = NonPosFloat(0f)
// nonPosFloat0: Type = 0.0F
val nonPosFloatMinus999 = NonPosFloat(-999.999f)
// nonPosFloatMinus999: Type = -999.999F

nonPosFloat0.value
// res228: Float = 0.0F

nonPosFloatMinus999.value
// res229: Float = -999.999F

Min and Max Values

NonPosFloat.MinValue
// res230: Type = -3.4028235E38F

NonPosFloat.MaxValue
// res231: Type = 0.0F

Refined BigInt

NegBigInt: negative BigInt

Compile-time Validation

NegBigInt(-1)
// res232: Type = -1
NegBigInt(0)
// error:
// Invalid value: [BigInt.apply(0)]. It must be a negative BigInt
NegBigInt(1)
// error:
// Invalid value: [BigInt.apply(1)]. It must be a negative BigInt

Runtime Validation

val validNegBigInt = -1 
// validNegBigInt: Int = -1
NegBigInt.from(validNegBigInt)
// res233: Either[String, Type] = Right(value = -1)
val invalidNegBigInt1 = 0 
// invalidNegBigInt1: Int = 0
NegBigInt.from(invalidNegBigInt1)
// res234: Either[String, Type] = Left(
// value = "Invalid value: [0]. It must be a negative BigInt"
// )

val invalidNegBigInt2 = 1
// invalidNegBigInt2: Int = 1
NegBigInt.from(invalidNegBigInt2)
// res235: Either[String, Type] = Left(
// value = "Invalid value: [1]. It must be a negative BigInt"
// )

Comparison

val negBigInt1 = NegBigInt(-1)
// negBigInt1: Type = -1
val negBigInt2 = NegBigInt(-2)
// negBigInt2: Type = -2

negBigInt1 > negBigInt2
// res236: Boolean = true
negBigInt1 >= negBigInt2
// res237: Boolean = true
negBigInt1 == negBigInt2
// res238: Boolean = false
negBigInt1 < negBigInt2
// res239: Boolean = false
negBigInt1 <= negBigInt2
// res240: Boolean = false

Get Value

val negBigInt123 = NegBigInt(-123)
// negBigInt123: Type = -123
val negBigInt999 = NegBigInt(-999)
// negBigInt999: Type = -999

negBigInt123.value
// res241: BigInt = -123

negBigInt999.value
// res242: BigInt = -999

NonNegBigInt: non-negative BigInt

Compile-time Validation

NonNegBigInt(0)
// res243: Type = 0
NonNegBigInt(1)
// res244: Type = 1
NonNegBigInt(-2)
// error:
// Invalid value: [BigInt.apply(-2)]. It must be a non-negative BigInt

Runtime Validation

val validNonNegBigInt = 1 
// validNonNegBigInt: Int = 1
NonNegBigInt.from(validNonNegBigInt)
// res245: Either[String, Type] = Right(value = 1)
val invalidNonNegBigInt1 = -1
// invalidNonNegBigInt1: Int = -1
NonNegBigInt.from(invalidNonNegBigInt1)
// res246: Either[String, Type] = Left(
// value = "Invalid value: [-1]. It must be a non-negative BigInt"
// )

val invalidNonNegBigInt2 = -999
// invalidNonNegBigInt2: Int = -999
NonNegBigInt.from(invalidNonNegBigInt2)
// res247: Either[String, Type] = Left(
// value = "Invalid value: [-999]. It must be a non-negative BigInt"
// )

Comparison

val nonNegBigInt1 = NonNegBigInt(0)
// nonNegBigInt1: Type = 0
val nonNegBigInt2 = NonNegBigInt(999)
// nonNegBigInt2: Type = 999

nonNegBigInt1 > nonNegBigInt2
// res248: Boolean = false
nonNegBigInt1 >= nonNegBigInt2
// res249: Boolean = false
nonNegBigInt1 == nonNegBigInt2
// res250: Boolean = false
nonNegBigInt1 < nonNegBigInt2
// res251: Boolean = true
nonNegBigInt1 <= nonNegBigInt2
// res252: Boolean = true

Get Value

val nonNegBigInt123 = NonNegBigInt(0)
// nonNegBigInt123: Type = 0
val nonNegBigInt999 = NonNegBigInt(999)
// nonNegBigInt999: Type = 999

nonNegBigInt123.value
// res253: BigInt = 0

nonNegBigInt999.value
// res254: BigInt = 999

PosBigInt: positive BigInt

Compile-time Validation

PosBigInt(1)
// res255: Type = 1
PosBigInt(999)
// res256: Type = 999
PosBigInt(0)
// error:
// Invalid value: [BigInt.apply(0)]. It must be a positive BigInt
PosBigInt(-2)
// error:
// Invalid value: [BigInt.apply(-2)]. It must be a positive BigInt

Runtime Validation

val validPosBigInt = 1
// validPosBigInt: Int = 1
PosBigInt.from(validPosBigInt)
// res257: Either[String, Type] = Right(value = 1)
val invalidPosBigInt1 = 0
// invalidPosBigInt1: Int = 0
PosBigInt.from(invalidPosBigInt1)
// res258: Either[String, Type] = Left(
// value = "Invalid value: [0]. It must be a positive BigInt"
// )

val invalidPosBigInt2 = -999
// invalidPosBigInt2: Int = -999
PosBigInt.from(invalidPosBigInt2)
// res259: Either[String, Type] = Left(
// value = "Invalid value: [-999]. It must be a positive BigInt"
// )

Comparison

val posBigInt1 = PosBigInt(1)
// posBigInt1: Type = 1
val posBigInt2 = PosBigInt(999)
// posBigInt2: Type = 999

posBigInt1 > posBigInt2
// res260: Boolean = false
posBigInt1 >= posBigInt2
// res261: Boolean = false
posBigInt1 == posBigInt2
// res262: Boolean = false
posBigInt1 < posBigInt2
// res263: Boolean = true
posBigInt1 <= posBigInt2
// res264: Boolean = true

Get Value

val posBigInt123 = PosBigInt(123)
// posBigInt123: Type = 123
val posBigInt999 = PosBigInt(999)
// posBigInt999: Type = 999

posBigInt123.value
// res265: BigInt = 123

posBigInt999.value
// res266: BigInt = 999

NonPosBigInt: non-positive BigInt

Compile-time Validation

NonPosBigInt(0)
// res267: Type = 0
NonPosBigInt(-999)
// res268: Type = -999
NonPosBigInt(1)
// error:
// Invalid value: [BigInt.apply(1)]. It must be a non-positive BigInt

Runtime Validation

val validNonPosBigInt = 0
// validNonPosBigInt: Int = 0
NonPosBigInt.from(validNonPosBigInt)
// res269: Either[String, Type] = Right(value = 0)

val validNonPosBigInt2 = -999
// validNonPosBigInt2: Int = -999
NonPosBigInt.from(validNonPosBigInt2)
// res270: Either[String, Type] = Right(value = -999)
val invalidNonPosBigInt1 = 1
// invalidNonPosBigInt1: Int = 1
NonPosBigInt.from(invalidNonPosBigInt1)
// res271: Either[String, Type] = Left(
// value = "Invalid value: [1]. It must be a non-positive BigInt"
// )

val invalidNonPosBigInt2 = 999
// invalidNonPosBigInt2: Int = 999
NonPosBigInt.from(invalidNonPosBigInt2)
// res272: Either[String, Type] = Left(
// value = "Invalid value: [999]. It must be a non-positive BigInt"
// )

Comparison

val nonPosBigInt1 = NonPosBigInt(0)
// nonPosBigInt1: Type = 0
val nonPosBigInt2 = NonPosBigInt(-999)
// nonPosBigInt2: Type = -999

nonPosBigInt1 > nonPosBigInt2
// res273: Boolean = true
nonPosBigInt1 >= nonPosBigInt2
// res274: Boolean = true
nonPosBigInt1 == nonPosBigInt2
// res275: Boolean = false
nonPosBigInt1 < nonPosBigInt2
// res276: Boolean = false
nonPosBigInt1 <= nonPosBigInt2
// res277: Boolean = false

Get Value

val nonPosBigInt0 = NonPosBigInt(0)
// nonPosBigInt0: Type = 0
val nonPosBigIntMinus999 = NonPosBigInt(-999)
// nonPosBigIntMinus999: Type = -999

nonPosBigInt0.value
// res278: BigInt = 0

nonPosBigIntMinus999.value
// res279: BigInt = -999

Refined BigDecimal

NegBigDecimal: negative BigDecimal

Compile-time Validation

NegBigDecimal(-0.00001d)
// res280: Type = -0.000010
NegBigDecimal(-999.999d)
// res281: Type = -999.999
NegBigDecimal(0d)
// error:
// Invalid value: [BigDecimal.apply(0.0d)]. It must be a negative BigDecimal
NegBigDecimal(999.999d)
// error:
// Invalid value: [BigDecimal.apply(999.999d)]. It must be a negative BigDecimal

Runtime Validation

val validNegBigDecimal = -0.00001d 
// validNegBigDecimal: Double = -1.0E-5
NegBigDecimal.from(validNegBigDecimal)
// res282: Either[String, Type] = Right(value = -0.000010)
val invalidNegBigDecimal1 = 0d 
// invalidNegBigDecimal1: Double = 0.0
NegBigDecimal.from(invalidNegBigDecimal1)
// res283: Either[String, Type] = Left(
// value = "Invalid value: [0.0]. It must be a negative BigDecimal"
// )

val invalidNegBigDecimal2 = 999.999d
// invalidNegBigDecimal2: Double = 999.999
NegBigDecimal.from(invalidNegBigDecimal2)
// res284: Either[String, Type] = Left(
// value = "Invalid value: [999.999]. It must be a negative BigDecimal"
// )

Comparison

val negBigDecimal1 = NegBigDecimal(-0.1d)
// negBigDecimal1: Type = -0.1
val negBigDecimal2 = NegBigDecimal(-0.2d)
// negBigDecimal2: Type = -0.2

negBigDecimal1 > negBigDecimal2
// res285: Boolean = true
negBigDecimal1 >= negBigDecimal2
// res286: Boolean = true
negBigDecimal1 == negBigDecimal2
// res287: Boolean = false
negBigDecimal1 < negBigDecimal2
// res288: Boolean = false
negBigDecimal1 <= negBigDecimal2
// res289: Boolean = false

Get Value

val negBigDecimal123 = NegBigDecimal(-123.123d)
// negBigDecimal123: Type = -123.123
val negBigDecimal999 = NegBigDecimal(-999.999d)
// negBigDecimal999: Type = -999.999

negBigDecimal123.value
// res290: BigDecimal = -123.123

negBigDecimal999.value
// res291: BigDecimal = -999.999

NonNegBigDecimal: non-negative BigDecimal

Compile-time Validation

NonNegBigDecimal(0d)
// res292: Type = 0.0
NonNegBigDecimal(999.999d)
// res293: Type = 999.999
NonNegBigDecimal(-0.00001d)
// error:
// Invalid value: [BigDecimal.apply(-1.0E-5d)]. It must be a non-negative BigDecimal
NonNegBigDecimal(-999.999d)
// error:
// Invalid value: [BigDecimal.apply(-999.999d)]. It must be a non-negative BigDecimal

Runtime Validation

val validNonNegBigDecimal1 = 0d
// validNonNegBigDecimal1: Double = 0.0
NonNegBigDecimal.from(validNonNegBigDecimal1)
// res294: Either[String, Type] = Right(value = 0.0)

val validNonNegBigDecimal2 = 999.999d
// validNonNegBigDecimal2: Double = 999.999
NonNegBigDecimal.from(validNonNegBigDecimal2)
// res295: Either[String, Type] = Right(value = 999.999)
val invalidNonNegBigDecimal1 = -0.00001d
// invalidNonNegBigDecimal1: Double = -1.0E-5
NonNegBigDecimal.from(invalidNonNegBigDecimal1)
// res296: Either[String, Type] = Left(
// value = "Invalid value: [-0.000010]. It must be a non-negative BigDecimal"
// )

val invalidNonNegBigDecimal2 = -999.999d
// invalidNonNegBigDecimal2: Double = -999.999
NonNegBigDecimal.from(invalidNonNegBigDecimal2)
// res297: Either[String, Type] = Left(
// value = "Invalid value: [-999.999]. It must be a non-negative BigDecimal"
// )

Comparison

val nonNegBigDecimal1 = NonNegBigDecimal(0d)
// nonNegBigDecimal1: Type = 0.0
val nonNegBigDecimal2 = NonNegBigDecimal(0.999d)
// nonNegBigDecimal2: Type = 0.999

nonNegBigDecimal1 > nonNegBigDecimal2
// res298: Boolean = false
nonNegBigDecimal1 >= nonNegBigDecimal2
// res299: Boolean = false
nonNegBigDecimal1 == nonNegBigDecimal2
// res300: Boolean = false
nonNegBigDecimal1 < nonNegBigDecimal2
// res301: Boolean = true
nonNegBigDecimal1 <= nonNegBigDecimal2
// res302: Boolean = true

Get Value

val nonNegBigDecimal123 = NonNegBigDecimal(0d)
// nonNegBigDecimal123: Type = 0.0
val nonNegBigDecimal999 = NonNegBigDecimal(999.999d)
// nonNegBigDecimal999: Type = 999.999

nonNegBigDecimal123.value
// res303: BigDecimal = 0.0

nonNegBigDecimal999.value
// res304: BigDecimal = 999.999

PosBigDecimal: positive BigDecimal

Compile-time Validation

PosBigDecimal(0.00001d)
// res305: Type = 0.000010
PosBigDecimal(999.999d)
// res306: Type = 999.999
PosBigDecimal(0d)
// error:
// Invalid value: [BigDecimal.apply(0.0d)]. It must be a positive BigDecimal
PosBigDecimal(-999.999d)
// error:
// Invalid value: [BigDecimal.apply(-999.999d)]. It must be a positive BigDecimal

Runtime Validation

val validPosBigDecimal1 = 0.00001d
// validPosBigDecimal1: Double = 1.0E-5
PosBigDecimal.from(validPosBigDecimal1)
// res307: Either[String, Type] = Right(value = 0.000010)

val validPosBigDecimal2 = 999.999d
// validPosBigDecimal2: Double = 999.999
PosBigDecimal.from(validPosBigDecimal2)
// res308: Either[String, Type] = Right(value = 999.999)
val invalidPosBigDecimal1 = 0d
// invalidPosBigDecimal1: Double = 0.0
PosBigDecimal.from(invalidPosBigDecimal1)
// res309: Either[String, Type] = Left(
// value = "Invalid value: [0.0]. It must be a positive BigDecimal"
// )

val invalidPosBigDecimal2 = -999.999d
// invalidPosBigDecimal2: Double = -999.999
PosBigDecimal.from(invalidPosBigDecimal2)
// res310: Either[String, Type] = Left(
// value = "Invalid value: [-999.999]. It must be a positive BigDecimal"
// )

Comparison

val posBigDecimal1 = PosBigDecimal(0.00001d)
// posBigDecimal1: Type = 0.000010
val posBigDecimal2 = PosBigDecimal(0.999d)
// posBigDecimal2: Type = 0.999

posBigDecimal1 > posBigDecimal2
// res311: Boolean = false
posBigDecimal1 >= posBigDecimal2
// res312: Boolean = false
posBigDecimal1 == posBigDecimal2
// res313: Boolean = false
posBigDecimal1 < posBigDecimal2
// res314: Boolean = true
posBigDecimal1 <= posBigDecimal2
// res315: Boolean = true

Get Value

val posBigDecimal123 = PosBigDecimal(123.123d)
// posBigDecimal123: Type = 123.123
val posBigDecimal999 = PosBigDecimal(999.999d)
// posBigDecimal999: Type = 999.999

posBigDecimal123.value
// res316: BigDecimal = 123.123

posBigDecimal999.value
// res317: BigDecimal = 999.999

NonPosBigDecimal: non-positive BigDecimal

Compile-time Validation

NonPosBigDecimal(0d)
// res318: Type = 0.0
NonPosBigDecimal(-999.999d)
// res319: Type = -999.999
NonPosBigDecimal(0.00001d)
// error:
// Invalid value: [BigDecimal.apply(1.0E-5d)]. It must be a non-positive BigDecimal
NonPosBigDecimal(999.999d)
// error:
// Invalid value: [BigDecimal.apply(999.999d)]. It must be a non-positive BigDecimal

Runtime Validation

val validNonPosBigDecimal = 0d
// validNonPosBigDecimal: Double = 0.0
NonPosBigDecimal.from(validNonPosBigDecimal)
// res320: Either[String, Type] = Right(value = 0.0)

val validNonPosBigDecimal2 = -999.999d
// validNonPosBigDecimal2: Double = -999.999
NonPosBigDecimal.from(validNonPosBigDecimal2)
// res321: Either[String, Type] = Right(value = -999.999)
val invalidNonPosBigDecimal1 = 0.00001d
// invalidNonPosBigDecimal1: Double = 1.0E-5
NonPosBigDecimal.from(invalidNonPosBigDecimal1)
// res322: Either[String, Type] = Left(
// value = "Invalid value: [0.000010]. It must be a non-positive BigDecimal"
// )

val invalidNonPosBigDecimal2 = 999.999d
// invalidNonPosBigDecimal2: Double = 999.999
NonPosBigDecimal.from(invalidNonPosBigDecimal2)
// res323: Either[String, Type] = Left(
// value = "Invalid value: [999.999]. It must be a non-positive BigDecimal"
// )

Comparison

val nonPosBigDecimal1 = NonPosBigDecimal(0d)
// nonPosBigDecimal1: Type = 0.0
val nonPosBigDecimal2 = NonPosBigDecimal(-0.999d)
// nonPosBigDecimal2: Type = -0.999

nonPosBigDecimal1 > nonPosBigDecimal2
// res324: Boolean = true
nonPosBigDecimal1 >= nonPosBigDecimal2
// res325: Boolean = true
nonPosBigDecimal1 == nonPosBigDecimal2
// res326: Boolean = false
nonPosBigDecimal1 < nonPosBigDecimal2
// res327: Boolean = false
nonPosBigDecimal1 <= nonPosBigDecimal2
// res328: Boolean = false

Get Value

val nonPosBigDecimal0 = NonPosBigDecimal(0d)
// nonPosBigDecimal0: Type = 0.0
val nonPosBigDecimalMinus999 = NonPosBigDecimal(-999.999d)
// nonPosBigDecimalMinus999: Type = -999.999

nonPosBigDecimal0.value
// res329: BigDecimal = 0.0

nonPosBigDecimalMinus999.value
// res330: BigDecimal = -999.999

Refined NonEmptyString

Compile-time Validation

NonEmptyString("blah")
// res331: Type = "blah"
NonEmptyString("Lorem Ipsum is simply dummy text of the printing and typesetting industry.")
// res332: Type = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
NonEmptyString("")
// error:
// Invalid value: [""]. It must be a non-empty String

Runtime Validation

val validNonEmptyString1 = "blah" 
// validNonEmptyString1: String = "blah"
NonEmptyString.from(validNonEmptyString1)
// res333: Either[String, Type] = Right(value = "blah")

val validNonEmptyString2 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
// validNonEmptyString2: String = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
NonEmptyString.from(validNonEmptyString2)
// res334: Either[String, Type] = Right(
// value = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
// )
val invalidNonEmptyString = "" 
// invalidNonEmptyString: String = ""
NonEmptyString.from(invalidNonEmptyString)
// res335: Either[String, Type] = Left(
// value = "Invalid value: []. It must be a non-empty String"
// )

Concatenation

val nonEmptyString1 = NonEmptyString("Hello")
// nonEmptyString1: Type = "Hello"
val nonEmptyString2 = NonEmptyString(" World")
// nonEmptyString2: Type = " World"

nonEmptyString1 ++ nonEmptyString2
// res336: Type = "Hello World"

Get Value

val nonEmptyStringA = NonEmptyString("blah")
// nonEmptyStringA: Type = "blah"
val nonEmptyStringB = NonEmptyString("Lorem Ipsum is simply dummy text of the printing and typesetting industry.")
// nonEmptyStringB: Type = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."

nonEmptyStringA.value
// res337: String = "blah"

nonEmptyStringB.value
// res338: String = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."

Refined NonBlankString

Compile-time Validation

NonBlankString("blah")
// res339: Type = "blah"
NonBlankString("Lorem Ipsum is simply dummy text of the printing and typesetting industry.")
// res340: Type = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
// error:
// NonBlankString("")
// ^^^^^^^^^^^^^^^^^^
// Invalid value: [""]. It must be not all whitespace non-empty String

NonBlankString(" ")
// error:
// NonBlankString(" ")
// ^^^^^^^^^^^^^^^^^^^
// Invalid value: [" "]. It must be not all whitespace non-empty String

NonBlankString(" \t \n \r")
// error:
// NonBlankString(" \t \n \r")
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Invalid value: [" \t \n \r"]. It must be not all whitespace non-empty String

Runtime Validation

val validNonBlankString1 = "blah"
// validNonBlankString1: String = "blah"
NonBlankString.from(validNonBlankString1)
// res341: Either[String, Type] = Right(value = "blah")

val validNonBlankString2 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
// validNonBlankString2: String = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
NonBlankString.from(validNonBlankString2)
// res342: Either[String, Type] = Right(
// value = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
// )
val invalidNonBlankString1 = ""
// invalidNonBlankString1: String = ""
NonBlankString.from(invalidNonBlankString1)
// res343: Either[String, Type] = Left(
// value = "Invalid value: [], unicode=[]. It must be not all whitespace non-empty String"
// )

val invalidNonBlankString2 = " "
// invalidNonBlankString2: String = " "
NonBlankString.from(invalidNonBlankString2)
// res344: Either[String, Type] = Left(
// value = "Invalid value: [ ], unicode=[\\u0020]. It must be not all whitespace non-empty String"
// )

val invalidNonBlankString3 = " \t \n \r"
// invalidNonBlankString3: String = """
//
"""
NonBlankString.from(invalidNonBlankString3)
// res345: Either[String, Type] = Left(
// value = """Invalid value: [
//
], unicode=[\u0020\u0009\u0020\u000a\u0020\u000d]. It must be not all whitespace non-empty String"""
// )

Concatenation

val nonBlankString1 = NonBlankString("Hello")
// nonBlankString1: Type = "Hello"
val nonBlankString2 = NonBlankString(" World")
// nonBlankString2: Type = " World"

nonBlankString1 ++ nonBlankString2
// res346: Type = "Hello World"

nonBlankString1.appendString(" ")
// res347: Type = "Hello "

nonBlankString1.prependString(" ")
// res348: Type = " Hello"

Get Value

val nonBlankStringA = NonBlankString("blah")
// nonBlankStringA: Type = "blah"
val nonBlankStringB = NonBlankString("Lorem Ipsum is simply dummy text of the printing and typesetting industry.")
// nonBlankStringB: Type = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."

nonBlankStringA.value
// res349: String = "blah"

nonBlankStringB.value
// res350: String = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."

Refined Uuid

Compile-time Validation

import refined4s.types.all.*
Uuid("3596f062-a6bd-4d2c-978e-3ed6f97a264b")
// res352: Type = "3596f062-a6bd-4d2c-978e-3ed6f97a264b"

val uuid1 = java.util.UUID.randomUUID()
// uuid1: UUID = 5700e9f1-2f57-4d07-b289-c739876d9e5f
Uuid(uuid1)
// res353: Type = "5700e9f1-2f57-4d07-b289-c739876d9e5f"
Uuid("")
// error:
// Invalid value: [""]. It must be UUID

Uuid("blah")
// error:
// Invalid value: ["blah"]. It must be UUID

Runtime Validation

val validUuidString = "3596f062-a6bd-4d2c-978e-3ed6f97a264b" 
// validUuidString: String = "3596f062-a6bd-4d2c-978e-3ed6f97a264b"
Uuid.from(validUuidString)
// res354: Either[String, Type] = Right(
// value = "3596f062-a6bd-4d2c-978e-3ed6f97a264b"
// )
val invalidUuid = "iuhsfd9f-f32wfwf3-d1i2j" 
// invalidUuid: String = "iuhsfd9f-f32wfwf3-d1i2j"
Uuid.from(invalidUuid)
// res355: Either[String, Type] = Left(
// value = "Invalid value: [iuhsfd9f-f32wfwf3-d1i2j]. It must be UUID"
// )

To java.util.UUID

val uuid2 = Uuid("3596f062-a6bd-4d2c-978e-3ed6f97a264b")
// uuid2: Type = "3596f062-a6bd-4d2c-978e-3ed6f97a264b"

uuid2.toUUID
// res356: UUID = 3596f062-a6bd-4d2c-978e-3ed6f97a264b

Get Value

val uuid3 = Uuid("3596f062-a6bd-4d2c-978e-3ed6f97a264b")
// uuid3: Type = "3596f062-a6bd-4d2c-978e-3ed6f97a264b"

uuid3.value
// res357: String = "3596f062-a6bd-4d2c-978e-3ed6f97a264b"

Refined Uri

Compile-time Validation

Uri("https://www.google.com")
// res358: Type = "https://www.google.com"
Uri("https://github.com/kevin-lee")
// res359: Type = "https://github.com/kevin-lee"
Uri("%^<>[]`{}")
// error:
// Invalid value: ["%^<>[]`{}"]. It must be a URI String

Runtime Validation

val validUri1 = "https://www.google.com" 
// validUri1: String = "https://www.google.com"
Uri.from(validUri1)
// res360: Either[String, Type] = Right(value = "https://www.google.com")

val validUri2 = "https://github.com/kevin-lee"
// validUri2: String = "https://github.com/kevin-lee"
Uri.from(validUri2)
// res361: Either[String, Type] = Right(value = "https://github.com/kevin-lee")
val invalidUri = "%^<>[]`{}" 
// invalidUri: String = "%^<>[]`{}"
Uri.from(invalidUri)
// res362: Either[String, Type] = Left(
// value = "Invalid value: [%^<>[]`{}]. It must be a URI String"
// )

Get Value

val uriA = Uri("https://www.google.com")
// uriA: Type = "https://www.google.com"
val uriB = Uri("https://github.com/kevin-lee")
// uriB: Type = "https://github.com/kevin-lee"

uriA.value
// res363: String = "https://www.google.com"

uriB.value
// res364: String = "https://github.com/kevin-lee"

Convert to java.net.URI

uriA.toURI
// res365: URI = https://www.google.com

uriB.toURI
// res366: URI = https://github.com/kevin-lee