Skip to content

Instantly share code, notes, and snippets.

@automationhacks
Created June 16, 2019 12:24
Show Gist options
  • Save automationhacks/079cb645eda698f3e87c1358a98ede00 to your computer and use it in GitHub Desktop.
Save automationhacks/079cb645eda698f3e87c1358a98ede00 to your computer and use it in GitHub Desktop.
Refactoring above code to use Extension functions
package _03_functions
fun String.getFirstWord(separator: String = " "): String {
return this.split(separator)[0]
}
fun main() {
val first = "Jane Doe".getFirstWord()
println("First word: $first")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment