windowedAndTransform<R> method

Iterable<R> windowedAndTransform<R>({
  1. required int size,
  2. required R transform(
    1. Iterable<E> chunk
    ),
  3. int step = 1,
  4. bool partialWindows = false,
})

Returns a Iterable of results of applying the given transform function to an each Iterable representing a view over the window of the given size sliding along this collection with the given step.

Implementation

Iterable<R> windowedAndTransform<R>({
  required int size,
  required R Function(Iterable<E> chunk) transform,
  int step = 1,
  bool partialWindows = false,
}) {
  if (size <= 0) {
    throw ArgumentError.value(size, 'size', 'must be greater than zero');
  }

  if (step <= 0) {
    throw ArgumentError.value(step, 'step', 'must be greater than zero');
  }

  final length = partialWindows
      ? (this.length / step).ceil()
      : (this.length - size) ~/ step + 1;

  return Iterable.generate(
    length,
    (index) => transform(skip(index * step).take(size)),
  );
}