Represents a configuration value or a composition of multiple values.
If a configuration value is missing, we can use ConfigValue#or to
try and load the value from elsewhere. ConfigValue#default can be
used to set a default value if all other values are missing. If the
value is optional, ConfigValue#option can be used to default
to None if all values are missing.
Values can be converted to a different type using ConfigValue#as. If the value might contain sensitive details, ConfigValue#secret can be used to redact sensitive details from error messages while also wrapping the value in Secret, preventing the value from being shown.
Sometimes, we first need to load a configuration value to determine
how to continue loading the remaining values. In such cases, it's
suitable to use ConfigValue#flatMap. When loading values in
sequence using flatMap, errors are not accumulated, and so
only the first error will be available.
Parallel composition lets us achieve error accumulation. Functions
like parMapN and parTupled on tuples of ConfigValues loads
several values while also accumulating errors. It is often helpful
to see all errors when loading configurations, so prefer options
which accumulate errors.
Configuration values can be loaded using ConfigValue#load, which
loads the value using a specified effect type. If a ConfigValue
contains Resources for loading the configuration, there is also
the option to return a Resource with ConfigValue#resource.
Attributes
- Example:
scala> import cats.syntax.all._ import cats.syntax.all._ scala> case class Config(maxRetries: Int, apiKey: Option[Secret[String]]) class Config scala> val maxRetries = env("MAX_RETRIES").or(prop("max.retries")).as[Int].default(5) val maxRetries: ConfigValue[[x]Effect[x],Int] = ConfigValue$$88354410 scala> val apiKey = env("API_KEY").or(prop("api.key")).secret.option val apiKey: ConfigValue[[x]Effect[x],Option[Secret[String]]] = ConfigValue$$2109306667 scala> val config = (maxRetries, apiKey).parMapN(Config(_, _)) val config: ConfigValue[[x]Effect[x],Config] = ConfigValue$$1463229407- Companion:
- object
- Graph
- Supertypes
- class Objecttrait Matchableclass Any