July 2018
Intermediate to advanced
242 pages
8h 6m
English
Once we declare proper componentN functions, we can benefit from destructuring of the LightBulb type objects:
val (id, turnedOn) = LightBulb(1)print("Light bulb number $id is turned ${if (turnedOn) "on" else "off"}")
This code would print the following output to the console:
Light bulb number 1 is turned off
As you can see, the component1() function was assigned to the first variable of the destructured declaration—id. Similarly, the second turnedOn variable was assigned with the result of the component2() function.
Read now
Unlock full access