https://github.com/pschiffmann/lookaround-iterator.dart
Provides an iterator class with lookbehind and lookahead buffer.
https://github.com/pschiffmann/lookaround-iterator.dart
Last synced: 8 months ago
JSON representation
Provides an iterator class with lookbehind and lookahead buffer.
- Host: GitHub
- URL: https://github.com/pschiffmann/lookaround-iterator.dart
- Owner: pschiffmann
- License: mit
- Created: 2017-08-13T01:05:22.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-11-08T18:14:21.000Z (over 7 years ago)
- Last Synced: 2025-10-22T23:54:24.705Z (8 months ago)
- Language: Dart
- Homepage: https://pub.dartlang.org/packages/lookaround_iterator
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Dart lookaround iterator
========================
[](https://travis-ci.com/pschiffmann/lookaround-iterator.dart)
The `LookaroundIterator` class exposes a fixed number of elements in the past and future of the current iteration element.
```Dart
// `it` is an iterator over a list of the numbers 1..10, currently
// pointing at `4`.
final it = LookaroundIterator(
List.generate(10, (n) => n + 1).iterator,
lookbehind: 2,
lookahead: 3)
..moveNext()
..moveNext()
..moveNext()
..moveNext();
// Prints _2, 3, 4, 5, 6, 7_.
// Notice the negative start index and the inclusive range `<=`.
for (int i = -it.lookbehind; i <= it.lookahead; i++) {
print(it[i]);
}
```