October 2019
Intermediate to advanced
434 pages
11h 54m
English
Let's start by adding support for adding a soda to our order:
sealed class Soda(name: String) : Item(name)object Coke : Soda("Coke")object Sprite : Soda("Sprite")object Dr_Pepper : Soda("Dr Pepper")
val order = order { this.items[Coke] = this.items.getOrDefault(Coke, 0) + 1}
This works, but is verbose and requires direct interaction with the underlying data structure. Let's improve this by making the syntax more natural and by hiding the data structure.
There are a couple of ways in which we can do this, as follows:
Read now
Unlock full access