Refined4s
Newtypes and Refinement types for Scala 3
Project | Maven Central |
---|---|
refined4s-core | |
refined4s-cats | |
refined4s-chimney | |
refined4s-circe | |
refined4s-pureconfig | |
refined4s-doobie-ce2 | |
refined4s-doobie-ce3 | |
refined4s-extras-render | |
refined4s-tapir |
Getting Started
To get refined4s
for your project,
refined4s-core
- sbt
- sbt (with libraryDependencies)
- scala-cli
In build.sbt
,
"io.kevinlee" %% "refined4s-core" % "0.19.0"
In build.sbt
,
libraryDependencies += "io.kevinlee" %% "refined4s-core" % "0.19.0"
//> using dep "io.kevinlee::refined4s-core:0.19.0"
refined4s-cats
- sbt
- sbt (with libraryDependencies)
- scala-cli
In build.sbt
,
"io.kevinlee" %% "refined4s-cats" % "0.19.0"
In build.sbt
,
libraryDependencies += "io.kevinlee" %% "refined4s-cats" % "0.19.0"
//> using dep "io.kevinlee::refined4s-cats:0.19.0"
refined4s-chimney
- sbt
- sbt (with libraryDependencies)
- scala-cli
In build.sbt
,
"io.kevinlee" %% "refined4s-chimney" % "0.19.0"
In build.sbt
,
libraryDependencies += "io.kevinlee" %% "refined4s-chimney" % "0.19.0"
//> using dep "io.kevinlee::refined4s-chimney:0.19.0"
refined4s-circe
- sbt
- sbt (with libraryDependencies)
- scala-cli
In build.sbt
,
"io.kevinlee" %% "refined4s-circe" % "0.19.0"
In build.sbt
,
libraryDependencies += "io.kevinlee" %% "refined4s-circe" % "0.19.0"
//> using dep "io.kevinlee::refined4s-circe:0.19.0"
refined4s-pureconfig
- sbt
- sbt (with libraryDependencies)
- scala-cli
In build.sbt
,
"io.kevinlee" %% "refined4s-pureconfig" % "0.19.0"
In build.sbt
,
libraryDependencies += "io.kevinlee" %% "refined4s-pureconfig" % "0.19.0"
//> using dep "io.kevinlee::refined4s-pureconfig:0.19.0"
refined4s-doobie-ce2
- sbt
- sbt (with libraryDependencies)
- scala-cli
In build.sbt
,
"io.kevinlee" %% "refined4s-doobie-ce2" % "0.19.0"
In build.sbt
,
libraryDependencies += "io.kevinlee" %% "refined4s-doobie-ce2" % "0.19.0"
//> using dep "io.kevinlee::refined4s-doobie-ce2:0.19.0"
refined4s-doobie-ce3
- sbt
- sbt (with libraryDependencies)
- scala-cli
In build.sbt
,
"io.kevinlee" %% "refined4s-doobie-ce3" % "0.19.0"
In build.sbt
,
libraryDependencies += "io.kevinlee" %% "refined4s-doobie-ce3" % "0.19.0"
//> using dep "io.kevinlee::refined4s-doobie-ce3:0.19.0"
refined4s-extras-render
- sbt
- sbt (with libraryDependencies)
- scala-cli
In build.sbt
,
"io.kevinlee" %% "refined4s-extras-render" % "0.19.0"
In build.sbt
,
libraryDependencies += "io.kevinlee" %% "refined4s-extras-render" % "0.19.0"
//> using dep "io.kevinlee::refined4s-extras-render:0.19.0"
refined4s-tapir
- sbt
- sbt (with libraryDependencies)
- scala-cli
In build.sbt
,
"io.kevinlee" %% "refined4s-tapir" % "0.19.0"
In build.sbt
,
libraryDependencies += "io.kevinlee" %% "refined4s-tapir" % "0.19.0"
//> using dep "io.kevinlee::refined4s-tapir:0.19.0"
All refined4s modules
- sbt
- sbt (with libraryDependencies)
- scala-cli
In build.sbt
,
"io.kevinlee" %% "refined4s-core" % "0.19.0",
"io.kevinlee" %% "refined4s-cats" % "0.19.0",
"io.kevinlee" %% "refined4s-chimney" % "0.19.0",
"io.kevinlee" %% "refined4s-circe" % "0.19.0",
"io.kevinlee" %% "refined4s-pureconfig" % "0.19.0",
"io.kevinlee" %% "refined4s-doobie-ce2" % "0.19.0", // Use either refined4s-doobie-ce2
"io.kevinlee" %% "refined4s-doobie-ce3" % "0.19.0", // OR refined4s-doobie-ce3
"io.kevinlee" %% "refined4s-extras-render" % "0.19.0",
"io.kevinlee" %% "refined4s-tapir" % "0.19.0",
In build.sbt
,
libraryDependencies ++= Seq(
"io.kevinlee" %% "refined4s-core" % "0.19.0",
"io.kevinlee" %% "refined4s-cats" % "0.19.0",
"io.kevinlee" %% "refined4s-chimney" % "0.19.0",
"io.kevinlee" %% "refined4s-circe" % "0.19.0",
"io.kevinlee" %% "refined4s-pureconfig" % "0.19.0",
"io.kevinlee" %% "refined4s-doobie-ce2" % "0.19.0", // Use either refined4s-doobie-ce2
"io.kevinlee" %% "refined4s-doobie-ce3" % "0.19.0", // OR refined4s-doobie-ce3
"io.kevinlee" %% "refined4s-extras-render" % "0.19.0",
"io.kevinlee" %% "refined4s-tapir" % "0.19.0",
)
//> using dep "io.kevinlee::refined4s-core:0.19.0"
//> using dep "io.kevinlee::refined4s-cats:0.19.0"
//> using dep "io.kevinlee::refined4s-chimney:0.19.0"
//> using dep "io.kevinlee::refined4s-circe:0.19.0"
//> using dep "io.kevinlee::refined4s-pureconfig:0.19.0"
//> using dep "io.kevinlee::refined4s-doobie-ce2:0.19.0" // Use either refined4s-doobie-ce2
//> using dep "io.kevinlee::refined4s-doobie-ce3:0.19.0" // OR refined4s-doobie-ce3
//> using dep "io.kevinlee::refined4s-extras-render:0.19.0"
//> using dep "io.kevinlee::refined4s-tapir:0.19.0"
Why refined4s
?
Given the following methods
def hello(name: String): Unit = println(s"Hello $name")
def sendEmail(email: String): Unit = {
println(s"Sending email to [email address: $email]")
// ... send email
}
You can easily mess up method parameters like this.
val name = "Kevin"
// name: String = "Kevin"
val email = "blah@blah.blah"
// email: String = "blah@blah.blah"
hello(email)
// Hello blah@blah.blah
sendEmail(name)
// Sending email to [email address: Kevin]
If you use refined4s
, you don't need to worry about that anymore.
import refined4s.*
type Name = Name.Type
object Name extends Newtype[String]
type Email = Email.Type
object Email extends Newtype[String]
def hello(name: Name): Unit = println(s"Hello ${name.value}")
def sendEmail(email: Email): Unit = {
println(s"Sending email to [email address: ${email.value}]")
// ... send email
}
You can easily mess up method parameters like this.
If you pass the right types, it works.
val name = Name("Kevin")
// name: Type = "Kevin"
val email = Email("blah@blah.blah")
// email: Type = "blah@blah.blah"
hello(name)
// Hello Kevin
sendEmail(email)
// Sending email to [email address: blah@blah.blah]
If you don't, it does not compile.
hello(email)
sendEmail(name)
// error:
// Found: (repl.MdocSession.MdocApp1.email : repl.MdocSession.MdocApp1.Email.Type)
// Required: repl.MdocSession.MdocApp1.Name
// error:
// Found: (repl.MdocSession.MdocApp1.name : repl.MdocSession.MdocApp1.Name.Type)
// Required: repl.MdocSession.MdocApp1.Email
// error:
// Line is indented too far to the left, or a `}` is missing
// error:
// Line is indented too far to the left, or a `}` is missing
// error:
// Line is indented too far to the left, or a `}` is missing