Cats Module

The ciris-cats module provides type class instances for contexts F[_] from cats when used together with Ciris. Id is the default context, and is used when no explicit context is desired. The ciris-cats module is useful in cases when F is not Id, but for example Future, like in the following example. Note that Ciris does not provide type class instances for any other contexts than Id and relies on instances for other contexts from libraries like cats.

Let’s define an example ConfigSource which reads Future values.

import cats.implicits._
import ciris._
import ciris.cats._
import ciris.ConfigError.right
import scala.concurrent._
import scala.concurrent.duration._

implicit val executionContext: ExecutionContext =
  ExecutionContext.Implicits.global

val source: ConfigSource[Future, String, String] = {
  val keyType = ConfigKeyType[String]("example key")
  ConfigSource.applyF(keyType) { key: String =>
    Future.successful(right(key.length.toString))
  }
}

We can then load, decode, and combine values into a configuration as follows.

final case class Config(first: Int, second: Int)
// defined class Config

val futureConfig =
  loadConfig(
    source.read("firstKey").decodeValue[Int],
    source.read("secondKey").decodeValue[Int]
  )(Config)
// futureConfig: ciris.ConfigResult[scala.concurrent.Future,Config] = ConfigResult$559484486

val config = Await.result(futureConfig.result, 1.second)
// config: Either[ciris.ConfigErrors,Config] = Right(Config(8,9))

The ciris-cats module also provides Show type class instances for logging configurations.