v0.7.0
0.7.0 - 2023-12-30
Changes
- [
refined4s-cats
] RenamevalidateAs
inrefined4s.modules.cats.syntax
torefinedNewtypeNec
(#182)
-
[
refined4s-core
] MovetoValue
fromrefined4s.syntax
torefined4s.NewtypeBase
(#186)So with the given following code,
import refined4s.* import refined4s.types.all.* type Name = Name.Type object Name extends Newtype[NonEmptyString]
the following is possible without importing any
syntax
.val name = Name(NonEmptyString("Kevin")) name.toValue // String = "Kevin"
New Features
-
[
refined4s-cats
] AddrefinedNewtypeNel
inrefined4s.modules.cats.syntax
(#184)import refined4s.* import refined4s.types.all.* import refined4s.modules.cats.syntax.* type Name = Name.Type object Name extends Newtype[NonEmptyString] "Kevin".refinedNewtypeNel[Name] // EitherNel[String, Name] = Right(Name(NonEmptyString("Kevin"))) "".refinedNewtypeNel[Name] // EitherNel[String, Name] = Left(NonEmptyList("Failed to create Name: Invalid value: []. It has to be a non-empty String but got \"\"))
-
[
refined4s-cats
] AddvalidateAs
inrefined4s.modules.cats.syntax
to validate a value and returnValidated
(#188)import refined4s.* import refined4s.types.all.* import refined4s.modules.cats.syntax.* type Name = Name.Type object Name extends Newtype[NonEmptyString] "Kevin".validateAs[Name] // Validated[String, Name] = Valid(Name(NonEmptyString("Kevin"))) "".validateAs[Name] // Validated[String, Name] = Invalid("Failed to create Name: Invalid value: []. It has to be a non-empty String but got \"\")
-
[
refined4s-cats
] AddvalidateNecAs
inrefined4s.modules.cats.syntax
to validate a value and returnValidatedNec
(#189)import refined4s.* import refined4s.types.all.* import refined4s.modules.cats.syntax.* type Name = Name.Type object Name extends Newtype[NonEmptyString] "Kevin".validateNecAs[Name] // ValidatedNec[String, Name] = Valid(Name(NonEmptyString("Kevin"))) "".validateNecAs[Name] // ValidatedNec[String, Name] = Invalid(NonEmptyChain("Failed to create Name: Invalid value: []. It has to be a non-empty String but got \"\"))
-
[
refined4s-cats
] AddvalidateNelAs
inrefined4s.modules.cats.syntax
to validate a value and returnValidatedNel
(#190)import refined4s.* import refined4s.types.all.* import refined4s.modules.cats.syntax.* type Name = Name.Type object Name extends Newtype[NonEmptyString] "Kevin".validateNelAs[Name] // ValidatedNel[String, Name] = Valid(Name(NonEmptyString("Kevin"))) "".validateNelAs[Name] // ValidatedNel[String, Name] = Invalid(NonEmptyList("Failed to create Name: Invalid value: []. It has to be a non-empty String but got \"\"))
-
[
refined4s-cats
] AddderivedOrder
to have the instance ofOrder[A]
derived fromCoercible[A, B]
andOrder[B]
(#194)Given
import refined4s.* type MyNum = MyNum.Type object MyNum extends Newtype[Int]
it can be
import cats.* val n1 = MyNum(1) val n2 = MyNum(2) Order[MyNum].compare(n1, n2) // Int = -1
-
[
refined4s-core
] AddCanBeOrdered
for providingOrdering
andConversion[Type, Ordered[Type]]
(#196)import refined4s.* type MyNum = MyNum.Type object MyNum extends Newtype[Int]
val input1 = MyNum(1) val input2 = MyNum(2) Ordering[MyNum].compare(input1, input2) // Int = -1 (input1: Ordered[MyNum]).compare(input2) // Int = -1
- [
refined4s-core
] MakeNonEmptyString
CanBeOrdered
to haveOrdering[NonEmptyString]
andConversion[NonEmptyString, Ordered[NonEmptyString]]
(#198)
- [
refined4s-cats
] AddCatsOrder
(#203)import refined4s.* type MyNum = MyNum.Type object MyNum extends Newtype[Int], CatsOrder[Int]
import cats.* val myNum1 = NyNum(1) val myNum2 = NyNum(2) Order[MyNum].compare(myNum1, myNum1) // Int = 0 Order[MyNum].compare(myNum1, myNum2) // Int = -1 Order[MyNum].compare(myNum2, myNum1) // Int = 1
Internal Changes
- [
refined4s-core
] ReplaceOrdering
andConversion[Type, Ordered[Type]]
for numeric types withCanBeOrdered
(#199)