startFrom method

OffsetIterator<T> startFrom(
  1. int? offset, {
  2. String name = 'startFrom',
  3. bool? cancelOnError,
  4. bool bubbleCancellation = true,
})

Pull from the OffsetIterator from the specified offset.

Implementation

OffsetIterator<T> startFrom(
  int? offset, {
  String name = 'startFrom',
  bool? cancelOnError,
  bool bubbleCancellation = true,
}) {
  final parent = this;

  return OffsetIterator(
    name: toStringWithChild(name),
    init: () => offset ?? parent.offset,
    process: (offset) {
      final earliest = parent.earliestAvailableOffset - 1;
      if (offset < earliest) offset = earliest;

      final futureOr = parent.pull(offset);

      if (futureOr is Future<Option<T>>) {
        return futureOr.then((item) => OffsetIteratorState(
              acc: offset + 1,
              chunk: item is Some ? [(item as Some).value] : null,
              hasMore: parent.hasMore(offset + 1),
            ));
      }

      return OffsetIteratorState(
        acc: offset + 1,
        chunk: futureOr is Some ? [(futureOr as Some).value] : null,
        hasMore: parent.hasMore(offset + 1),
      );
    },
    cleanup: parent.generateCleanup(bubbleCancellation: bubbleCancellation),
    cancelOnError: cancelOnError ?? parent.cancelOnError,
    seed: parent.generateSeed(startOffset: offset),
  );
}