Data Pipeline Patterns
Take and Skip
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
void main() {
var values = [1, 2, 3, 4, 5];
var window = values.skip(1).take(3).toList();
var text = window.join('-');
print(text);
}
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`.