types.Array.replace_with
Overwrites this array's elements with other's.
The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing
... from the prose below, not from the signature.Parameters
other | array | the array to copy elements from |
Return value
This array.
Notes
The new length matches other, so this can grow or shrink the array, unlike apply. The elements themselves are copied by reference, the same as slice and clone: a table or array element ends up shared between this array and other afterward.
replace is a deprecated alias for this function.
Example
let a = [1, 2, 3, 4];
let src = [7, 8];
let same = a.replace_with(src);
println("same == a:", same == a); // returns this array
println("a.len() =", a.len()); // length now matches src, not the old length
println("a =", ", ".join(a.map(@(v) v.tostring())));Output:
same == a: true
a.len() = 2
a = 7, 8See also
clone | Makes a shallow copy of the array. |
extend | Appends every element of other to this array. |
| array | class index |