package refined
- Alphabetic
- By Inheritance
- refined
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- final case class PartialRefinedPath[FAP]() extends Product with Serializable
Value Members
- implicit def deriveRefinedDescriptor[A, P](implicit desc: Descriptor[A], validate: Validate[A, P]): Descriptor[Refined[A, P]]
FIXME Automatically derive instances of Descriptor for any refined types
FIXME Automatically derive instances of Descriptor for any refined types
- Annotations
- @silent("deprecated")
- def refine[Predicate]: PartialRefined[Predicate]
refine[Predicate] allows to retrieve a
refined
type given an existingConfigDescriptor
and a predicate Predicate.refine[Predicate] allows to retrieve a
refined
type given an existingConfigDescriptor
and a predicate Predicate. Example of a Predicate isNonEmpty
.Example:
import zio.config.magnolia.descriptor final case class MyConfig(url: String, port: Int) val configs: ConfigDescriptor[List[MyConfig]] = list("databases")(descriptor[MyConfig]) val configDescriptor: ConfigDescriptor[Refined[List[MyConfig], Size[Greater[W.`2`.T]]]] = refined[Size[Greater[W.`2`.T]]](configs)
If you don't care predicates specifically, and need to pass a fully formed Refined type (Example: type NonEmptyString = String Refined NonEmpty), refer
refineType[RefinedType]
- def refine[A, P](path: String)(implicit desc: Descriptor[A], validate: Validate[A, P]): config.ConfigDescriptor[Refined[A, P]]
refine
allows us to retrieve arefined
type from a given path.refine
allows us to retrieve arefined
type from a given path.Example:
import eu.timepit.refined.string._ val configDescriptor: ConfigDescriptor[Refined[String, Uuid]] = refined[String, Uuid]("ID")
- Annotations
- @silent("deprecated")
- def refineType[R]: PartialRefinedPath[R]
refineType[RefinedType] allows to retrieve a RefinedType (example: NonEmptyString) from a path.
refineType[RefinedType] allows to retrieve a RefinedType (example: NonEmptyString) from a path.
Unlike
refine[Predicate]
method,refineType[RefinedType]
allows you to a pass a fully formed refined type and be careless about theConfigDescriptor
of the underlying type.Example:
type NonEmptyString = String Refined NonEmpty refineType[NonEmptyString]("USERNAME") // is same as val userName: ConfigDescriptor[String] = string("USERNAME") refine[NonEmpty](userName)
While,
refineType[RefinedType]
is useful for simple application,refine[Predicate]
can be more flexible in complex configurations where you need more orthogonality between raw config and refined configs.refine[Predicate]
allows you to build entire ConfigDescriptor without worrying aboutRefined
modules, allowing you to then pass theConfigDescriptor[RawConfig]
torefine[Predicate]
and refine the types, which is more into an orthogonal design.A complete example of refineType:
import zio.config._ import eu.timepit.refined.types.string.NonEmptyString final case class Jdbc(username: NonEmptyString, password: NonEmptyString) val jdbc: ConfigDescriptor[Jdbc] = (refineType[NonEmptyString]("username") zip refineType[NonEmptyString]("password")).to[Jdbc]