baml.deep_copy

Returns a deep copy of `value`: nested arrays, maps, and class instances are cloned recursively.

Reference version

Signature

function baml.deep_copy<T>(value: T) -> T throws never

Returns a deep copy of value: nested arrays, maps, and class instances are cloned recursively.

Sharing and cycles survive the copy. Two references to the same nested object still point at one copied object afterward, rather than becoming independent copies. Future is the exception — a future is a handle onto live async state the runtime owns, not a value with contents to clone, so a future nested inside value is shared, not duplicated.

Source:<builtin>/baml/core.bamlbytes 510–582