Cats Effect Module

The ciris-cats-effect module provides effect types and effect type class instances for contexts F[_] from cats-effect. Effect types are useful for explicitly modelling side-effects, including suspending effects for reading configuration values. Ciris provides functions envF, propF, and fileSync and fileWithNameSync, which suspend the reading in a context F[_], for which there is a Sync instance available.

import ciris.{propF, fileSync}
// import ciris.{propF, fileSync}

import ciris.cats.effect._
// import ciris.cats.effect._

import cats.effect.IO
// import cats.effect.IO

// Suspend reading of system property file.encoding as a String
propF[IO, String]("file.encoding")
// res1: ciris.ConfigEntry[cats.effect.IO,String,String,String] = ConfigEntry(file.encoding, Property)

// Suspend reading the file, trim the file contents, and convert to Int
fileSync[IO, Int](tempFile, _.trim)
// res3: ciris.ConfigEntry[cats.effect.IO,(, java.nio.charset.Charset),String,Int] = ConfigEntry((/var/folders/ff/tg7g7zh52_g9s5_djb5z81w00000gn/T/temp-4386652450588370328.tmp,UTF-8), ConfigKeyType(file))

If we have a Sync instance for F[_], we can take an existing ConfigSource and create a new ConfigSource with suspended reading using the suspendF function. If we also need to memoize the results, there is a suspendMemoizeF function for that purpose.

import ciris.ConfigSource
// import ciris.ConfigSource

import ciris.cats.effect.syntax._
// import ciris.cats.effect.syntax._

// res4: ciris.ConfigSource[cats.effect.IO,String,String] = ConfigSource(Property)

// res5: ciris.ConfigSource[[v]cats.effect.IO[cats.effect.IO[v]],String,String] = ConfigSource(Property)

The supporting new sources section contains an example of how these functions can be used.