Created
June 16, 2019 12:24
-
-
Save automationhacks/079cb645eda698f3e87c1358a98ede00 to your computer and use it in GitHub Desktop.
Refactoring above code to use Extension functions
This file contains 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
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