Last Updated: September 01, 2020
· colindean

A simple environment-based config Scala object for a simple app or script

case class Config(input: String, output: String)
val config =
      List(inputTableEnvvar, outputTableEnvvar)
    .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

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.