Spire Module

The ciris-spire module enables decoding of spire number types. For a complete list of supported types, refer to the documentation. Let’s see how we can decode spire number types by first defining a custom configuration source from which to load some configuration values.

import ciris.{ConfigKeyType, ConfigSource}
import ciris.spire._
import spire.math._

val source = {
  val keyType = ConfigKeyType[String]("spire key")
  ConfigSource.fromEntries(keyType)(
    "natural" -> "847365894625891365137596378546725",
    "interval" -> "(1/3, 524/51]",
    "rational" -> "-194712/-129831",
    "uint" -> (Int.MaxValue.toLong + 1L).toString
  )
}

We can then read entries from the source and decode values into spire number types.

source.read("natural").decodeValue[Natural]
// res0: ciris.ConfigEntry[ciris.api.Id,String,String,spire.math.Natural] = ConfigEntry(natural, ConfigKeyType(spire key))

source.read("interval").decodeValue[Interval[Rational]]
// res1: ciris.ConfigEntry[ciris.api.Id,String,String,spire.math.Interval[spire.math.Rational]] = ConfigEntry(interval, ConfigKeyType(spire key))

source.read("rational").decodeValue[Rational]
// res2: ciris.ConfigEntry[ciris.api.Id,String,String,spire.math.Rational] = ConfigEntry(rational, ConfigKeyType(spire key))

source.read("natural").decodeValue[Number]
// res3: ciris.ConfigEntry[ciris.api.Id,String,String,spire.math.Number] = ConfigEntry(natural, ConfigKeyType(spire key))

source.read("rational").decodeValue[Real]
// res4: ciris.ConfigEntry[ciris.api.Id,String,String,spire.math.Real] = ConfigEntry(rational, ConfigKeyType(spire key))

source.read("trilean").decodeValue[Trilean]
// res5: ciris.ConfigEntry[ciris.api.Id,String,String,spire.math.Trilean] = ConfigEntry(trilean, ConfigKeyType(spire key))

source.read("uint").decodeValue[UInt]
// res6: ciris.ConfigEntry[ciris.api.Id,String,String,spire.math.UInt] = ConfigEntry(uint, ConfigKeyType(spire key))