Giter VIP home page Giter VIP logo

iter-over's Introduction

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!).

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

iter-over's People

Contributors

t99 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

iter-over's Issues

[Symbol.iterator] function appears to call #next one-too-many times without returning

For some reason it appears that in the StringLineIterator class the #next function is called one-too-many times which results in the required type-check found here.

When used with a for ... of ([Symbol.iterator]) construct, there is always one final call to #next that does not return content to the iterator but that results in undefined being returned which was causing the call to String#trim() to throw a runtime error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.