Skip to content

Instantly share code, notes, and snippets.

@raecoo
Last active September 1, 2018 16:27
Show Gist options
  • Save raecoo/6ee002ea265c3bc33275b3465695239c to your computer and use it in GitHub Desktop.
Save raecoo/6ee002ea265c3bc33275b3465695239c to your computer and use it in GitHub Desktop.
Scala String Utils
def toCamel(s: String): String = {
val split = s.split("_")
val tail = split.tail.map { x => x.head.toUpper + x.tail }
split.head + tail.mkString
}
def camel2Underscore(text: String) = text.drop(1).foldLeft(text.headOption.map(_.toLower + "") getOrElse "") {
case (acc, c) if c.isUpper => acc + "_" + c.toLower
case (acc, c) => acc + c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment