Sometimes we need to deal with long or verbose type declarations. Thankfully, in Kotlin, we are able to assign an alternative name to any existing type and use the shorter alternative name instead. It can also help you to write more understandable and elegant code. This recipe is going to demonstrate how to use type aliases.
Wrapping complex type declarations with type aliases
Getting ready
Let's assume we have the following two classes predefined:
data class Song(val title: String)
data class Artist(val name: String)
We are going to define a type alias for the map of Song type values and a generic key type–Map<T, List<Song>>. Next, we are going to use it to define a function that will return the most...