Bringing it all together
While the aim of this chapter wasn’t to cover all of Kotlin’s syntax features—we’ll explore more throughout this book—this chapter is still fairly lengthy. Therefore, it’s a good time to practice what you’ve learned with a short exercise, if you’re interested.
Exercise
Write a function that takes a list of possibly nullable strings, each representing a sentence.
If a string is either null or empty, the function should print Skipped
.
Otherwise, the function should capitalize each word in the string.
The function should return a single list containing all the capitalized words.
Example
For the input listOf("hellO wOrlD", null, "fRom", null, "kOtlin")
, the function should return listOf("Hello", "World", "From", "Kotlin")
.
Challenge
Do you see an opportunity to use extension functions in this exercise...