getMany method

Result<Arr<T>, GetManyError> getMany(
  1. List<int> indices
)

Returns mutable references to many indices at once. Returns an error if any index is out-of-bounds.

Implementation

Result<Arr<T>, GetManyError> getMany(List<int> indices) {
  if (indices.length > _end - _start) {
    return const Err(GetManyErrorTooManyIndices());
  }
  if (indices.isEmpty) {
    return Ok(Arr.empty());
  }
  var array = Arr(this.first, indices.length);
  for (final (int i, int index) in indices.iter().enumerate()) {
    if (index < _start || index >= _end) {
      return const Err(GetManyErrorRequestedIndexOutOfBounds());
    }
    array[i] = this[index];
  }
  return Ok(array);
}