123456789101112131415161718192021222324252627282930313233343536373839404142 | '\" t
.\" Copyright (c) 2026 Bruce Hill
.\" All rights reserved.
.\"
.TH List.swap 3 2026-08-20 "Tomo man-pages"
.SH NAME
List.swap \- swap two elements in place
.SH LIBRARY
Tomo Standard Library
.SH SYNOPSIS
.nf
.BI List.swap\ :\ func(list:\ @[T],\ i:\ Int,\ j:\ Int\ ->\ Void)
.fi
.SH DESCRIPTION
Swaps the elements at two indices in place. Compiles inline, so a swap costs one bounds check per index and a single copy-on-write check (a two-element multi-assignment swap pays both twice). Swapping an index with itself is a no-op. Negative indices count from the back of the list, and an out-of-bounds index is a runtime error.
.SH ARGUMENTS
.TS
allbox;
lb lb lbx
l l l.
Name Type Description
list @[T] The mutable reference to the list.
i Int The index of the first element (1-indexed).
j Int The index of the second element (1-indexed).
.TE
.SH RETURN
Nothing.
.SH EXAMPLES
.EX
list := &[10, 20, 30]
list.swap(1, 3)
assert list == [30, 20, 10]
list.swap(2, -1)
assert list == [30, 10, 20]
.EE
.SH SEE ALSO
.BR Tomo-List (3)
|