Skip to content

Instantly share code, notes, and snippets.

@geraldcroes
Created December 9, 2017 17:03
Show Gist options
  • Select an option

  • Save geraldcroes/66c5a5523b7a8c21d557253f292a3410 to your computer and use it in GitHub Desktop.

Select an option

Save geraldcroes/66c5a5523b7a8c21d557253f292a3410 to your computer and use it in GitHub Desktop.
String extension
fun String.createFileParser() =
when (this.substringAfterLast('.')) {
"xml" -> XmlFileParser()
"json" -> JsonFileParser()
else -> throw Exception("I don't know how to deal with $this.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment