Review generated cart snapshot

from Data classes
Kotlin 2.4.10 advanced 6 min 4 issues to find

Review this generated cart-state update before it is used in an application store.

Return a new snapshot with one item appended and the revision incremented, without changing the input or disclosing the access token.

kotlin
data class CartSnapshot(
    val id: String,
    val accessToken: String,
    val items: MutableList<String>,
) {
    var revision: Int = 0
}

fun addItem(snapshot: CartSnapshot, item: String): CartSnapshot {
    val next = snapshot.copy()
    next.items += item
    next.revision = snapshot.revision + 1
    println("updated: $next")
    return next
}

generated code is illustrative, not from any one model

Open in playground
Report an error