Created
March 22, 2022 07:28
-
-
Save supermanue/b71a3eb77d9520320d39d91b983787b9 to your computer and use it in GitHub Desktop.
User with Refined types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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