<commit_before>package lenthall.config

import com.typesafe.config.Config

object ScalaConfig {

  implicit class EnhancedScalaConfig(val config: Config) extends AnyVal {
    def getConfigOption(key: String): Option[Config] = {
      if (config.hasPath(key)) Option(config.getConfig(key)) else None
    }

    def getStringOption(key: String): Option[String] = {
      if (config.hasPath(key)) Option(config.getString(key)) else None
    }

    def getBooleanOption(key: String): Option[Boolean] = {
      if (config.hasPath(key)) Option(config.getBoolean(key)) else None
    }

    def getIntOption(key: String): Option[Int] = {
      if (config.hasPath(key)) Option(config.getInt(key)) else None
    }

    def getLongOption(key: String): Option[Long] = {
      if (config.hasPath(key)) Option(config.getLong(key)) else None
    }

    def getDoubleOption(key: String): Option[Double] = {
      if (config.hasPath(key)) Option(config.getDouble(key)) else None
    }

    def getStringOr(key: String, default: => String = ""): String = {
      getStringOption(key) getOrElse default
    }

    def getBooleanOr(key: String, default: => Boolean = false): Boolean = {
      getBooleanOption(key) getOrElse default
    }

    def getIntOr(key: String, default: => Int = 0): Int = {
      getIntOption(key) getOrElse default
    }

    def getLongOr(key: String, default: => Long = 0L): Long = {
      getLongOption(key) getOrElse default
    }

    def getDoubleOr(key: String, default: => Double = 0.0): Double = {
      getDoubleOption(key) getOrElse default
    }
  }

}<commit_msg>There were multiple variants of this in Cromwell and Lenthall, reduce to a single one<commit_after>package lenthall.config

import com.typesafe.config.{ConfigException, Config}

import scala.util.Try

object ScalaConfig {

  implicit class EnhancedScalaConfig(val config: Config) extends AnyVal {
    def getConfigOption(key: String): Option[Config] = getOption(key, config.getConfig)
    def getStringOption(key: String): Option[String] = getOption(key, config.getString)
    def getBooleanOption(key: String): Option[Boolean] = getOption(key, config.getBoolean)
    def getIntOption(key: String): Option[Int] = getOption(key, config.getInt)
    def getLongOption(key: String): Option[Long] = getOption(key, config.getLong)
    def getDoubleOption(key: String): Option[Double] = getOption(key, config.getDouble)
    def getStringOr(key: String, default: => String = ""): String = getStringOption(key) getOrElse default
    def getBooleanOr(key: String, default: => Boolean = false): Boolean = getBooleanOption(key) getOrElse default
    def getIntOr(key: String, default: => Int = 0): Int = getIntOption(key) getOrElse default
    def getLongOr(key: String, default: => Long = 0L): Long = getLongOption(key) getOrElse default
    def getDoubleOr(key: String, default: => Double = 0.0): Double = getDoubleOption(key) getOrElse default

    private def getOption[T](key: String, f: String => T): Option[T] = {
      Try(f(key)) match {
        case scala.util.Success(value) => Option(value)
        case scala.util.Failure(e: ConfigException.Missing) => None
        case scala.util.Failure(e) => throw e
      }
    }
  }

}
{'fraction_non_alphanumeric': 0.12250623441396509, 'fraction_numerical': 0.0024937655860349127, 'mean_word_length': 4.006240249609984, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4932546', 'n_tokens_mistral': 1014, 'n_tokens_neox': 980, 'n_words': 252}