Case-modddels pattern matching
Let's continue with our Weather
example (find it here).
The super-sealed classes have additional "special" pattern matching methods that allow you to map between the different modddels. In our example, these methods are : mapWeather
, maybeMapWeather
and mapOrNullWeather
.
For Example :
In general, these methods are named 'map{ModddelName}', 'maybeMap{ModddelName}' and 'mapOrNull{ModddelName}'.
These methods can be used on all the super-sealed classes :
Super-sealed class | Case-Modddels you can map between |
---|---|
|
|
|
|
|
|
|
|
For Example :
Notice how the type of the callback parameters changes according to which super-sealed class the mapWeather
method is called on.
Last updated