October 2019
Intermediate to advanced
434 pages
11h 54m
English
Next up, let's see how we can map one value to another value. Let's map our string, "Kotlin", to a corresponding data type.
First, we'll create a sealed class to represent our programming languages:
sealed class ProgrammingLanguage(protected val name: String) { object Kotlin : ProgrammingLanguage("Kotlin") object Java : ProgrammingLanguage("Java") object Swift : ProgrammingLanguage("Swift") override fun toString(): String { return "$name Programming Language" }}
Next, we can add a call to the map() function to map our String items to a corresponding language. The map operator allows us to change our result type from the incoming data type to any outgoing data type we wish. In this case, we are mapping from String to ProgrammingLanguage ...
Read now
Unlock full access