Skip to content

Instantly share code, notes, and snippets.

@tkawachi
Created February 9, 2015 03:06
Show Gist options
  • Save tkawachi/1d26ad7ef840bc966949 to your computer and use it in GitHub Desktop.
Save tkawachi/1d26ad7ef840bc966949 to your computer and use it in GitHub Desktop.
import com.github.kxbmap.configs._
import com.typesafe.config.Config
object ConfigAny {
implicit class ConfigAnyImplicit(val config: Config) {
def optAny[A: AtPath](keys: Seq[String])(implicit cc: CatchCond = CatchCond.missing): Option[A] =
keys.foldLeft(None: Option[A]) { (a, e) => a.orElse(config.opt[A](e)) }
def getAny[A: AtPath](keys: Seq[String])(implicit cc: CatchCond = CatchCond.missing): A =
optAny(keys).getOrElse(sys.error(s"Any of $keys are not specified."))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment