OxL Reference

method List.insert

Inserts x before the element at index i; later elements move one place up. i == len() appends.

Example:

oxl✓ checked in CI
fn main() io {
  var xs = [1, 2, 4]
  xs.insert(2, 3)
  print("{xs}")
}
Output
[1, 2, 3, 4]

Inserts x before index i; later elements move up.

Example:

oxl✓ checked in CI
fn main() io {
  var xs = [1, 3]
  xs.insert(1, 2)
  print("{xs}")
}
Output
[1, 2, 3]
pub(api) var fn insert(i: usize, x: T)

Complexity. O(n) in the number of elements after `i`.

Since. 1.0.0-beta

Parameters

NameType
iusize
xT

Errors

panics when `i > len()`.

Effects

none declared (pure unless the body says otherwise)

Defined in: std/core/collections.oxl:211

See also