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

lazyer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazyer

Lazy iteration in JavaScript.

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

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

Lazyer

Lazy iteration in JavaScript.
Based heavily on the Rust iterator trait.

Overview

Lazyer allows for lazy iteration.
It can be used for working with finite sequences:

const lazy = require('lazyer');
lazy.from(people)
    .filter(person => person.age >= 65)
    .map(person => `${person.firstName} ${person.lastName}`)
    .map(name => name.toUpperCase())
    .forEach(name => console.log(name));

And infinite sequences:

const lazy = require('lazyer');

lazy.range()
    .scan(([a, b]) => [b, a + b], [0, 1])
    .map(([a]) => a)
    .take(10)
    .collect();
→ [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

Works with anything iterable:

const lazy = require('lazyer');
const string = 'Hello World!';
const set = new Set(string);

lazy.range(0)
    .zip(set)
    .collectMap()
→ Map {
    0 => 'H',
    1 => 'e',
    2 => 'l',
    3 => 'o',
    4 => ' ',
    5 => 'W',
    6 => 'r',
    7 => 'd',
    8 => '!'
}

And does a bunch of useful things:

const lazy = require('lazyer');
const longest = lazy.from(listOfListOfNodes)
    .flat()
    .flatMap(node => node.children)
    .max(node => node.data.length);

Functions

Functions that create a lazy iterator.

  • from
  • of
  • range
  • repeat
  • repeatWith
  • iterate

Adaptors

Methods that adapt the iterator.
A consumer needs to be called before any of these will be executed.

  • stepBy
  • skip
  • take
  • skipWhile
  • takeWhile
  • chunk
  • enumerate
  • concat
  • cycle
  • map
  • filter
  • scan
  • zip
  • flat
  • flatMap
  • join
  • joinWith
  • each

Consumers

Methods that consume the iterator.
These methods start the iteration.

  • next
  • peek
  • at
  • count
  • last
  • forEach
  • reduce
  • sum
  • product
  • find
  • findIndex
  • includes
  • every
  • some
  • max
  • min
  • maxBy
  • minBy
  • collect
  • partition
  • unzip
  • group
  • categorize
  • clone
  • cloneMany

Docs

See the documented source code.
And for examples, see the test file.

Keywords

FAQs

Package last updated on 02 Sep 2018

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