Skip to main content
Version: v0.x.0

Refined4s

Build Status Release Status Latest version

Refined4s Logo

Newtypes and Refinement types for Scala 3

ProjectMaven Central
refined4s-coreMaven Central
refined4s-catsMaven Central
refined4s-chimneyMaven Central
refined4s-circeMaven Central
refined4s-pureconfigMaven Central
refined4s-doobie-ce2Maven Central
refined4s-doobie-ce3Maven Central
refined4s-extras-renderMaven Central
refined4s-tapirMaven Central

Getting Started

To get refined4s for your project,

refined4s-core

In build.sbt,

"io.kevinlee" %% "refined4s-core" % "0.19.0"

refined4s-cats

In build.sbt,

"io.kevinlee" %% "refined4s-cats" % "0.19.0"

refined4s-chimney

In build.sbt,

"io.kevinlee" %% "refined4s-chimney" % "0.19.0"

refined4s-circe

In build.sbt,

"io.kevinlee" %% "refined4s-circe" % "0.19.0"

refined4s-pureconfig

In build.sbt,

"io.kevinlee" %% "refined4s-pureconfig" % "0.19.0"

refined4s-doobie-ce2

In build.sbt,

"io.kevinlee" %% "refined4s-doobie-ce2" % "0.19.0"

refined4s-doobie-ce3

In build.sbt,

"io.kevinlee" %% "refined4s-doobie-ce3" % "0.19.0"

refined4s-extras-render

In build.sbt,

"io.kevinlee" %% "refined4s-extras-render" % "0.19.0"

refined4s-tapir

In build.sbt,

"io.kevinlee" %% "refined4s-tapir" % "0.19.0"

All refined4s modules

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",

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