Skip to content

Instantly share code, notes, and snippets.

@dwalend
Created October 29, 2015 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwalend/cead7b8ecc384de582bc to your computer and use it in GitHub Desktop.
Save dwalend/cead7b8ecc384de582bc to your computer and use it in GitHub Desktop.
package net.shrine
import com.typesafe.config.Config
package object config {
/**
* @author dwalend
* @since July 17, 2015
*
* Helper methods for parsing com.typesafe.config.Config objects
*/
implicit class ConfigExtensions(self: Config) {
def get[T](key:String,construct:String => T):T = construct(self.getString(key))
def getConfigured[T](key: String, constructor: Config => T): T = constructor(self.getConfig(key))
def getOption[T](key: String, extract: Config => (String => T)): Option[T] = {
if (self.hasPath(key)) Option(extract(self)(key))
else None
}
def getOptionConfigured[T](key: String, constructor: Config => T): Option[T] = {
getOption(key, _.getConfig).map(constructor)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment