https://github.com/t99/iter-over
Sugary iteration utilities and interfaces.
https://github.com/t99/iter-over
async-iterable async-iterables async-iteration async-iterator async-iterators for-await for-await-of for-each for-in for-of iterable iterables iteration iterator iterators typescript
Last synced: 11 months ago
JSON representation
Sugary iteration utilities and interfaces.
- Host: GitHub
- URL: https://github.com/t99/iter-over
- Owner: T99
- License: gpl-3.0
- Created: 2019-06-07T23:35:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-11-02T12:34:56.000Z (about 4 years ago)
- Last Synced: 2025-02-16T11:55:25.784Z (11 months ago)
- Topics: async-iterable, async-iterables, async-iteration, async-iterator, async-iterators, for-await, for-await-of, for-each, for-in, for-of, iterable, iterables, iteration, iterator, iterators, typescript
- Language: TypeScript
- Homepage: https://T99.github.io/iter-over/
- Size: 714 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: license.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
iter-over
iter-over is an iteration toolset for JavaScript/TypeScript that provides interfaces as well as utility classes for
iteration using the native JavaScript Symbol.iterator method (and Symbol.asyncIterator!).
Find iter-over on NPM.
## Table of Contents
- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Documentation](#documentation)
- [License](#license)
## Installation
Install from NPM with
```
$ npm install --save iter-over
```
## Basic Usage
For most use-cases you'll want to extend `AbstractIterator` (the iter-over abstract iterator class). This abstract class
implements such methods as `#forEachRemaining(callback)` and automagically implements the `[Symbol.iterator]` method so
that you don't have to!
The only methods you have to implement are:
```typescript
public hasNext(): boolean { ... }
public next(): E | undefined { ... }
```
So for example, an inline implementation would look something like:
```typescript
import { AbstractIterator } from "iter-over";
class MyCounter extends AbstractIterator {
private val: number = 0;
public hasNext(): boolean {
return (this.val <= 9);
}
public next(): number {
return this.val++;
}
}
```
Once you've done that, you can freely use the iterator as such:
```typescript
let counter: MyCounter = new MyCounter();
for (let counterVal of counter) console.log(counterVal);
// ...console logs 0 through 9.
```
## Documentation
Full documentation can be found [here](https://t99.github.io/iter-over/)!
## License
iter-over is made available under the GNU General Public License v3.
Copyright (C) 2021 Trevor Sears