Skip to content

Instantly share code, notes, and snippets.

@ioleo
Created January 29, 2018 20:08
Show Gist options
  • Save ioleo/62057f8545d09890bb45b45487010bd3 to your computer and use it in GitHub Desktop.
Save ioleo/62057f8545d09890bb45b45487010bd3 to your computer and use it in GitHub Desktop.
Classy typesafe config reader utils
import classy.{DecodeError, Read}
import classy.config.ConfigDecoder
import com.typesafe.config.Config
import scala.util.{Failure, Success, Try}
object ConfigReader {
def apply[A](f: String => A): Read[Config, A] = { path =>
ConfigDecoder.instance[A] { config =>
Try(f(config.getString(path))) match {
case Success(value) => Right(value)
case Failure(ex) => Left(DecodeError.Underlying(ex))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment