The destructuring declaration

The destructuring declaration is nothing but a stylish way to extract the data from the model classes at the time of creation. Often, we wrap the data in a model and return it via a function. And on the caller end, we simply access its objects one by one. We actually never wanted an entire class here.

From the statistics object, we want to read the value and the count. Our getPollStatistics function cannot return multiple data, so we thought of returning a pair and we are destructuring the pair on the left hand side of assignment operator and use the unpacked data directly.

The signature of the function is as follows:

fun getPollStatistics(statistics: List<Statistics>): Pair<Int, Int>

And destructuring it and ...

Get Hands-On Serverless Applications with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.