isOutOfBounds<T> function

bool isOutOfBounds<T>(
  1. int index,
  2. ImmutableList<T> list
)

Checks if the given index is out of bounds for the provided list.

Determines whether the specified index is less than zero or greater than or equal to the length of the list. This is useful for validating index values before attempting to access or modify list items.

Usage:

var myList = ImmutableList([1, 2, 3, 4, 5]);
var isIndexOutOfBounds = isOutOfBounds(6, myList);  // Returns true
  • Parameters:
    • index: The index value to check.
    • list: The ImmutableList<T> against which the index will be checked.
  • Returns: true if the index is out of bounds, otherwise false.

Implementation

bool isOutOfBounds<T>(int index, ImmutableList<T> list) {
  return index < 0 || index >= list.items.length;
}