package iv_properties

import util.TODO

class LazyProperty(val initializer: () -> Int) {
    val lazy: Int = todoTask33()
}

fun todoTask33(): Nothing = TODO(
    """
        Task 33.
        Add a custom getter to make the 'lazy' val really lazy.
        It should be initialized by the invocation of 'initializer()'
        at the moment of the first access.
        You can add as many additional properties as you need.
        Do not use delegated properties!
    """,
    references = { LazyProperty({ 42 }).lazy }
)

package iv_properties

import util.TODO
import java.util.Objects.isNull

class LazyProperty(val initializer: () -> Int) {

    private var lazyValue : Int? = null

    val lazy: Int
        get() {
            if (isNull(lazyValue)) {
                lazyValue = initializer()
            }
            return lazyValue!!
        }
}

fun todoTask33(): Nothing = TODO(
    """
        Task 33.
        Add a custom getter to make the 'lazy' val really lazy.
        It should be initialized by the invocation of 'initializer()'
        at the moment of the first access.
        You can add as many additional properties as you need.
        Do not use delegated properties!
    """,
    references = { LazyProperty({ 42 }).lazy }
)

Complete koan 33 (lazily initialized property)
Complete koan 33 (lazily initialized property)

sleberknight/kotlin-koans,sleberknight/kotlin-koans