How it works...
We are delegating the var temperature variable to the result of the Delegates.vetoable() function, which returns an instance of the ReadWriteProperty class. That fact makes it possible to declare temperature as a mutable variable. The vetoable() function takes two arguments—the initial value, and an instance of the hook function that is going to be invoked on every change made to the delegated variable.
That function provides the current value of the delegated variable and a candidate for the new value. As the result, the function returns the Boolean—true if the value can be updated, and false if the update condition is not met. In our case, we are instantiating the function as the lambda block in which we check whether the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access