A simple environment-based config Scala object for a simple app or script
case class Config(input: String, output: String)
val config =
Some(
List(inputTableEnvvar, outputTableEnvvar)
.map(sys.env.get)
.flatten
)
.flatMap {
// you'll have to keep the parameters here
// aligned with parameters of the case class
case List(a: String, b: String) => Some( (a, b) )
case _ => None
}
.map(Config.tupled)
config
will be None
if the any of the environment variables aren't specified or return null. If you want to eliminate empty strings, add another map
before the flatten that handles that.
Written by Colin Dean
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Scala
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#