We all know and love the Kotlin Programming language. And we use one of its great features — Delegated Properties — relatively frequently (and sometimes we don’t know about it).

One of the most used delegated properties is Lazy, which is used for “lazy” initialization of values (that’s obvious, isn’t it?).

But Lazy in Kotlin has a significant drawback — you can’t update a value of the initialized variable. So, code like this one doesn’t work (pay attention to the “var” keyword in the very first line):

But sometimes we need it! That’s why I created my own implementation of delegated property for this purpose; here it is:

This implementation is quite simple, so I’m not going to explain how it works. Let me just say that our previous example may be rewritten in this way:

And it works like a charm!

--

--

Two months ago, digging through my old code, I found exciting sources — a simulation of book pages turning, which I did for one of my old projects. In addition to curling, the code supports zooming and dragging of the zoomed area as well.

I decided to comb this code, added caching in a background thread, put it in a separate library, and published it under the MIT license. The result looks like this:

If it’s interesting for you and you wish to use it in your applications, the source code can be found here.

--

--

Alexander Shevelev

Alexander Shevelev

An Android developer from Moscow, Russia. That’s all.