🚀 DAY 1 OF LAUNCH WEEK: Reachability for Ruby Now in Beta.Learn more →
Socket
Book a DemoInstallSign in
Socket

lazyrange

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazyrange

Speedy ranges for node, inspired by Python.

latest
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

lazyrange Build Status

Example


import range from 'lazyrange';

// for-of loops
for (let i of range(5)) {
    // 0, 1, 2, 3, 4
}

// array-like iteration
range(5, 10).each(function(i) {
    // 5, 6, 7, 8, 9
});

API

Creation

import range from 'lazyrange';

let foo = range(0, 5);
let bar = new range.Range(5, 0, -1);

new Range(end) -> Range

Creates a range starting at 0 and ending at end using a step of 1.

new Range(start, end, [step]) -> Range

Creates a range from start to end using a step that defaults to 1,

range( ... ) -> Range

Shortcut method to return a new instance of a range.

Methods

Range.prototype.toArray() -> Array

Evaluates the range into an array.

let arr = range(5).toArray();
// [0, 1, 2, 3, 4]

Range.prototype.map(callback) -> Array

Maps the range to an array.

var arr = range(5).map((value, index) => Math.pow(value, 2));
// [0, 1, 4, 9, 16]

Range.prototype.reduce(callback, memo) -> *

Reduces the range to a value.

var val = range(5).reduce((memo, value, index) => memo + value, 0);
// 10

Range.prototype.each(callback) | Range.prototype.forEach(callback)

Iterates over each value in the range.

range(5).each(function(value, index) {
    console.log(value);
});

for-of

Lazily iterate over each value in the range.

for (let i of range(5)) {

}

FAQs

Package last updated on 03 Jul 2015

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