Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@breautek/iterator

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@breautek/iterator

Simplistic iterator API for collection-like objects.

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

node-iterator

Simplistic iterator API.

Iterator

constructor(array)

Iterator takes one parameter, which is any array. The array is cloned, so modifying the array will not modify the behaviour of the Iterator instance.

var iterator = new Iterator(data);

hasNext(): boolean

Returns true if there are more items that have yet to be iterated through.

next(): any

Returns the next item.

hasPrevious(): boolean

Returns true if the iterator can back-step.

previous(): any

Returns the previous item

reset(): void

Sets the cursor back at the beginning

Example

var data = [1,2,3,4,5];
var iter = new Iterator(data);

iter.next(); // 1
iter.next(); // 2

iter.reset();

while (iter.hasNext()) {
    iter.next();
    /*
    1
    2
    3
    4
    5
    */
}

while(iter.hasPrevious()) {
    iter.previous();
    /*
    5
    4
    3
    2
    1
    */
}

Keywords

FAQs

Package last updated on 12 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc