Skip to content

Instantly share code, notes, and snippets.

@supermanue
Created March 22, 2022 07:28
Show Gist options
  • Save supermanue/b71a3eb77d9520320d39d91b983787b9 to your computer and use it in GitHub Desktop.
Save supermanue/b71a3eb77d9520320d39d91b983787b9 to your computer and use it in GitHub Desktop.
User with Refined types
object User {
sealed abstract case class User private (id: Id, name: Name)
object User {
def build(id: Int, name: String): Either[AppError, User] =
for {
refinedId <- toRefinedId(id)
refinedName <- toRefinedName(name)
} yield new User(refinedId, refinedName) {}
}
// previous GIST with refined type stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment