Skip to content
Oddly enough, a Scala wrapper for Typesafe's (pure-Java) Config library.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Oddly enough, a Scala wrapper for Typesafe's (pure-Java) Config library.


import com.typesafe.config._
import net.rosien.configz._
import scalaz._
import Scalaz._

val config = ConfigFactory.load // or some other constructor from com.typesafe.config

// Config instances may be appended using Config.withFallback() semantics. (Config has a Monoid[Config])
val combinedConfig = config |+| ConfigFactory.parseFile(...)

// Define some paths to values of a certain type.
val boolPath: Configz[Boolean] = "".path[Boolean]
val intPath:  Configz[Int]     = "".path[Int]

// Get the values at the path, which may fail with a com.typesafe.config.ConfigException.
val boolProp: Settings[Boolean] = config.get(boolPath)
val intProp:  Settings[Int]     = config.get(intPath)

// Note that Settings[A] is an alias for ValidationNEL[ConfigException, A].

// Configz is an applicative functor, so you can combine them (using scalaz operators like <*> or |@|):
val boolIntConfig: Configz[(Boolean, Int)]  = (boolPath |@| intPath)(_ -> _)
val boolIntProp:   Settings[(Boolean, Int)] = config.get(boolIntConfig)

// Configz paths can have custom validation:
val validatedIntPath = intPath.validate((_: Int) > 1000, " must be > 1000")
You can’t perform that action at this time.