nextChunk method

  1. @override
Result<Arr<T>, Iter<T>> nextChunk(
  1. int size
)

Returns the next n elements of the iterator as an Arr, If there are not enough elements to fill the array then Err is returned containing an iterator over the remaining elements.

Implementation

@override
Result<Arr<T>, Iter<T>> nextChunk(int size) {
  final arr = Arr<T?>(null, size);
  for (var i = 0; i < size; i++) {
    if (!moveNext()) {
      return Err(arr.take(i).cast<T>());
    }
    arr[i] = current;
  }
  return Ok(arr.cast<T>());
}