Because we have too few solutions
| Library | Docs | Types | Integrations | Notes |
|---|---|---|---|---|
| build-in | official | AnyVal extended by class with a single value |
many libraries support AnyVals |
- Scala 2/3, but on 3 it has a replacement - cannot always prevent boxing (unreliable) |
| build-in | official | opaque type |
vanilla version has no integrations | - Scala 3-only - always prevents boxing |
Scalaz (scalaz/scalaz) |
Type @@ Tag |
? | - Scala 2/3 - it's a hack but works |
|
Macwire (softwaremill/macwire) |
Type @@ Tag |
? | - Scala 2/3 - like Scalaz' version - only used for DI with Macwire |
|
NewType (estatico/scala-newtype) |
@newtype, @newsubtype macro annotations |
a lot, via Coercible type class |
- Scala 2-only (macro-annotations on Scala 3 are a blocker) - a lof of integrations - macro annotation conveniently rewrites methods into extension methods |
|
supertagged for scala (rudogma/scala-supertagged) |
Type @@ Tag, Newtype0, NewtypeT, Newtype - extended by companion objects |
possible, via Extractor type class |
- Scala 2-only - requires manually defining extension methods in companion object |
|
Monix’s Newtypes (monix/newtypes) |
official | Newtype, NewtypeWrapped, NewtypeValidated, NewtypeK, NewtypeCovariantK and NewSubtype variants - extended by companion objects |
possible, via HasExtractor and HasBuilder type classes |
- Scala 2/3 - requires manually defining extension methods in companion object |
neotype (kitlangton/neotype) |
TypeWrapper, Newtype, Subtype - extended by companion objects |
some, via WithType type class |
- Scala 3-only - allows validation of (some) input in compile-time - requires manually defining extension methods in companion object |
|
Yet Another Newtype Library - yantl (arturaz/yantl) |
official | Newtype.Of[Type], Newtype.ValidatedOf(...), Newtype.WithoutValidationOf[Type] extended by companion object |
possible, via Newtype.WithType or Newtype.WithUnvalidatedType type classes |
- Scala 3-only - requires manually defining extension methods in companion object |
refined (fthomas/refined) |
Type Refined Refinment |
a lot, via Validate type class |
- Scala 2/3 - allows compile-time validation of some values, but only on Scala 2 |
|
Iron (Iltotore/iron) |
official | `Type : | Refinment, RefinedTypeOps[Type, Refinement, OpaqueTypeName]` extended by companion object |
a lot via Constraint type class |
Refined4s (kevin-lee/refined4s) |
official | Refined[Type] , NewType[Type] extended by companion object |
some, via mixins to companion object or deriving method in companion |
- Scala 2/3 |