Giter VIP home page Giter VIP logo

iterator's Introduction

JSDSL - Iterator

A collection of classes that allow iteration over a predefined collection of elements.

Table of Contents

Installation

Install from NPM with

$ npm install --save @jsdsl/iterator

Basic Usage

The Iterator class has a handful of useful methods:

hasNext(): boolean;

next(): E | undefined;

forEach(callback: (element: E) => any): void;

remove?(): E | undefined;

reset?(): void;

Each of which help enable iteration over the elements underlying the Iterator.

Perhaps of more use is the AbstractIterator, for which only the first two of the methods mentioned above need to be implemented:

public abstract hasNext(): boolean;

public abstract next(): E | undefined;

Correctly implementing the above two methods will result in a class whose instances can be iterated over by a regular for...of loop:

class MyIterator extends AbstractIterator<any> { ... }

for (let element of new MyIterator()) { ... }

This package also includes the Iterable and AbstractIterable classes. The Iterable class represents some structure that can be iterated over, and exposes the following methods:

iterator(): Iterator<E>;

[Symbol.iterator](): IterableIterator<E>;

Meanwhile the AbstractIterable class does the small task of implementing the [Symbol.iterator] method, simply requiring the implementation of the iterator method:

public abstract iterator(): Iterator<E>;

Similar to the Iterator and AbstractIterator classes, correctly implementing the required methods will result in a class whose instances can also be iterated over by a regular for...of loop:

class MyIterable extends AbstractIterable<any> { ... }

for (let element of new MyIterable()) { ... }

Documentation

See the wiki for full documentation.

License

@jsdsl/iterator is made available under the GNU General Public License v3.

Copyright (C) 2021 Trevor Sears

iterator's People

Contributors

t99 avatar

Watchers

 avatar  avatar

iterator's Issues

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.