getMany method

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

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

Implementation

Result<Arr<T>, GetManyError> getMany(Arr<int> indices) {
  final Arr<T?> array = Arr(null, indices.length);
  final length = len();
  for (final (int i, int index) in indices.iter().enumerate()) {
    if (index < 0 || index >= length) {
      return const Err(GetManyErrorRequestedIndexOutOfBounds());
    }
    array[i] = getUnchecked(index);
  }
  return Ok(array.cast<T>());
}