Refined
What is Refined?
Refined is Newtype + validation. It lets you model validated domain values as types instead of using raw primitives everywhere.
A refined value keeps:
- the original value type (
String,Int, etc.) - validation logic (
predicate) - a clear error message (
invalidReason)
Import
import refined4s.*
Why Use Refined Types?
- Avoid primitive obsession by modeling domain meaning in the type.
- Catch invalid literals at compile-time when possible.
- Keep runtime validation explicit and total with
Either. - Make boundaries safer without sacrificing plain Scala values.
More About Refined Types:
🗃️ Pre-defined Types
3 items
📄️ Custom Inlined Numeric
InlinedNumeric* traits are helpers for creating custom numeric refined types with less boilerplate.
📄️ Inlined Custom Type
What is InlinedRefined?
📄️ Custom Type
What is a Custom Refined Type?