Last active
September 1, 2018 16:27
-
-
Save raecoo/6ee002ea265c3bc33275b3465695239c to your computer and use it in GitHub Desktop.
Scala String Utils
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
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