Skip to content

Instantly share code, notes, and snippets.

@deigote
Last active October 22, 2020 19:43
Show Gist options
  • Save deigote/ac022e38dd60757092eacbe1ba58b269 to your computer and use it in GitHub Desktop.
Save deigote/ac022e38dd60757092eacbe1ba58b269 to your computer and use it in GitHub Desktop.
Transform a human friendly string to camel case in Scala
def humanToCamel(original: String): String =
original
.foldLeft(("", true)) {
case ((acc, upper), e) => (if (e == ' ') acc else if (upper) acc + e.toUpper else acc + e, e == ' ')
}
._1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment