Version: v0.7.0 - Beta.  We welcome contributors & feedback.

Map.copy

copy($options = {}) -> map

Description

Copy the Map into a new Map.

Any elements that are Lists or Maps will also be copied, recursively.

$map1 = { a: 1, b: 2 }
$map2 = $map1.copy()

$map1.b = 11
$map2.b = 22

print($map1)
//= { a: 1, b: 11 }

print($map2)
//= { a: 1, b: 22 }

Options

Option Value Description
refs true/false All child List or Map objects will use references instead of duplicated copies. This is more memory efficient, but can result in hard-to-find bugs. We recommend only using this for very large data structures.
$map1 = { a: [1, 2, 3]  }
$map2 = $map1.copy(-refs)

$map2.a[1] = 111

$map1.a
//= [111, 2, 3]