references/sleep-functions/copy.md

GitHub

copy

Category: Utility

Source: https://sleep.dashnine.org/manual/copy.html


Synopsis

@ copy(@array)

Returns a shallow copy of the specified array.

$ copy($scalar)

Returns a shallow copy of the specified scalar.

% copy(%hash)

Returns a shallow copy of the specified hash.

Parameters

@array|$scalar|%hash - the data to copy.

Returns

A shallow copy of the specified data type.

Examples

Example:

@a = @(1, 2, 3, 4, 5);
@b = copy(@a);

@a[2] = "moo";

println("@a is now: " . @a);
println("@b is now: " . @b);

Output:

@a is now: @(1, 2, 'moo', 4, 5)
@b is now: @(1, 2, 3, 4, 5)

See Also

&add; &addAll; &remove; &removeAt; &removeAll; &splice