Created
October 29, 2015 15:56
-
-
Save dwalend/cead7b8ecc384de582bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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