Iterable.skip(n) returns a lazy Iterable that drops the first n elements; Iterable.take(n) returns a lazy Iterable of the next n elements at most. Chaining them carves a position-based window out of a list without copying any data, and .toList() materializes the window into a concrete List. Both operations are non-mutating, so the source list is unchanged.

Program

Play the program to drop the first value, keep the next three, and join the resulting window with dashes.

take_skip.dart
Replay: real traced execution (multi-file project)
void main() {
  var values = [1, 2, 3, 4, 5];
  var window = values.skip(1).take(3).toList();
  var text = window.join('-');
  print(text);
}
  1. values ← [1, 2, 3, 4, 5]

    1void main() {2  var values = [1, 2, 3, 4, 5];3  var window = values.skip(1).take(3).toList();
    values this step[1, 2, 3, 4, 5]values
  2. stage ← skip -> [2, 3, 4, 5]

    2var values = [1, 2, 3, 4, 5];3var window = values.skip(1).take(3).toList();4var text = window.join('-');
    values this stepskip -> [2, 3, 4, 5]stage
  3. stage ← take -> [2, 3, 4]

    2var values = [1, 2, 3, 4, 5];3var window = values.skip(1).take(3).toList();4var text = window.join('-');
    values this steptake -> [2, 3, 4]stage
  4. window ← [2, 3, 4]

    2var values = [1, 2, 3, 4, 5];3var window = values.skip(1).take(3).toList();4var text = window.join('-');
    values this step[2, 3, 4]window
  5. text ← 2-3-4

    3var window = values.skip(1).take(3).toList();4var text = window.join('-');5print(text);
    values this step2-3-4text[2, 3, 4]window
  6. print(text);

    4  var text = window.join('-');5  print(text);6}
    output2-3-4
    values this step2-3-4text
skip `list.skip(n)` returns a lazy `Iterable` of every element after the first `n`. The trace first re-visits the chain line to show `skip -> [2, 3, 4, 5]`.
take `iterable.take(n)` returns a lazy `Iterable` of the next `n` elements at most. The next visit shows `take -> [2, 3, 4]`, ignoring the trailing `5`.
windowing Chained `skip` and `take` carve a position-based window out of the source list without copying. `.toList()` materializes the final window into a concrete `List`.