Algosim documentation: swap

swap

Returns a container with two of its elements swapped.

Syntax

Description

If X is a container and i and j integers, then swap(X, i, j) returns X with its elements indexed by i and j swapped.

Negative indices count from the end of the container.

Examples

v ≔ SequenceVector(10)
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
swap(v, 1, −1)
(10, 2, 3, 4, 5, 6, 7, 8, 9, 1)

See also