Thread
#stdlib
    elizarov

    elizarov

    5 years ago
    Lenses if a functional solution to this problem. No, in imperative language you can do better. Just like with collections. How would you modify an an immutable collection efficiently? Imagine something like this:
    val list = … // some immutable list here
    val updated = list.mutate { 
       add(”…”) // efficiently perform a series of mutating operations
       add(”…”)
    }
    where
    mutate
    is a helper function that “opens” and efficiently rebuilds immutable structure:
    fun <T> List<T>.mutate(block: MutableList<T>.() -> Unit): List<T>
    You should have a similar API for immutable data classes:
    val person = Person(first = “John”, last = “Smith”) // immutable person object with lots of props
    val updated = person.mutate { 
       age = 31
       occuptation = “Manager”
    }
    It is considerably more readable than the solution with lenses.
    ilya.gorbunov

    ilya.gorbunov

    5 years ago
    elizarov: Interesting, how does it scale for nested immutable structures? 🤔
    elizarov

    elizarov

    5 years ago
    The slack channel is too small to explain it