Created
January 29, 2018 20:08
-
-
Save ioleo/62057f8545d09890bb45b45487010bd3 to your computer and use it in GitHub Desktop.
Classy typesafe config reader utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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