// Any payloads retain their concrete type, including nested references.
class Record {
    public var label: String
}
let record = Record(label: "first")
let child = List(10, "hello")
let lookup = Dictionary()
lookup.set("record", record)
lookup.set("values", child)
let entries = List(lookup, child)

// copy() separates the outer container and shares nested references.
let copied = entries.copy()
cast<List>(copied.get(1)).append(true)
print(child.len())
cast<Record>(cast<Dictionary>(entries.get(0)).get("record")).label = "updated"
print(record.label)
print(entries == copied)

// Dictionary snapshots are Lists in deterministic insertion order.
let keys = lookup.keys()
var index = 0
while index < keys.len() {
    let key = keys.get(index)
    print(key)
    print(type_of(lookup.get(key)))
    index = index + 1
}
