JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 30
  • Score
    100M100P100Q64184F
  • License GPL-3.0-or-later

Sugary iteration utilities and interfaces.

Package Exports

  • iter-over

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (iter-over) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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

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:

public hasNext(): boolean { ... }
public next(): E | undefined { ... }

So for example, an inline implementation would look something like:

import { AbstractIterator } from "iter-over";

class MyCounter extends AbstractIterator<number> {

    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:

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!

License

iter-over is made available under the GNU General Public License v3.

Copyright (C) 2021 Trevor Sears