Why it matters

Refined types add invariants to types. Understanding shapes type-safe Scala.

Advertisement

The architecture

Type: 'Int Refined Positive'.

Predicate part of type.

refined mechanicsRefined typevalue + predicateCompile-time checkfor literalsRuntime validationfor user inputScala 3 has iron: modern refinement types alternative
refined usage.
Advertisement

How it works end to end

Predicates: Positive, NonEmpty, MatchesRegex, etc.

Compile-time: refineMV for literals.

Runtime: refineV[Pred](value) returns Either.

Scala 3 alternative: iron.