New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lazily

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazily

Implements common array methods in a lazy manner. Nothing more.

  • 0.0.17
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
decreased by-56%
Maintainers
1
Weekly downloads
 
Created
Source

lazily

Implements common array methods in a lazy manner. Nothing more.

There's an async version of this library as well, called lazily-async. See https://github.com/isotropy/lazily-async

Installation

npm install lazily

Create a sequence

import { Seq } from "lazily";

const seq = Seq.of([1, 2, 3])
for (const i of seq) {
  console.log(i)
}

It's lazy

Sequences are lazy. For example, in the following example only one map() action is performed irrespective of the length of the sequence.

const seq = Seq.of([1, 2, 3])
  .map(x => x * 2)
  .first();

toArray()

Seq.of([1, 2, 3]).toArray()
// [1, 2, 3]

map(fn)

Seq.of([1, 2, 3])
  .map(x => x * 2)
  .toArray()
// [2, 4, 6]

filter(predicate)

Seq.of([1, 2, 3, 4])
  .filter(x => x > 2)
  .toArray()
//[3, 4]

exit(predicate)

Seq.of([1, 2, 3, 4, 5])
  .exit(x => x > 3)
  .toArray()
// [1, 2, 3]

exitAfter(predicate)

Similar to exit(), but includes the last item as well.

Seq.of([1, 2, 3, 4, 5])
  .exitAfter(x => x > 3)
  .toArray()
// [1, 2, 3, 4]

find(predicate)

Seq.of([1, 2, 3, 4, 5]).find(x => x * 10 === 30)
// 3

reduce(fn)

Seq.of([1, 2, 3, 4, 5])
  .reduce((acc, x) => acc + x, 0)
// 15

short-circuited reduce(fn, initialValue, stopPredicate)

Seq.of([1, 2, 3, 4, 5])
  .reduce((acc, x) => acc + x, 0, acc => acc > 6)
// 10

first()

Seq.of([1, 2, 3, 4, 5]).first();
// 1

first(predicate)

Seq.of([1, 2, 3, 4, 5]).first(x => x > 3);
// 4

last()

Seq.of([1, 2, 3, 4, 5]).last();
// 5

last(predicate)

Seq.of([1, 2, 3, 4, 5]).last(x => x < 3);
// 2

every(predicate)

Seq.of([1, 2, 3, 4, 5]).every(x => x <= 5);
// true

some(predicate)

Seq.of([1, 2, 3, 4, 5]).some(x => x === 3);
// true

includes(item)

Seq.of([1, 2, 3, 4, 5]).includes(3);
// true

concat(seq)

Seq.of([1, 2, 3, 4, 5]).concat(Seq.of([6, 7, 8])).toArray();
// [1, 2, 3, 4, 5, 6, 7, 8]

reverse()

Seq.of([1, 2, 3]).reverse().toArray();
// [3, 2, 1]

slice(begin, end)

Seq.of([1, 2, 3, 4, 5, 6]).slice(2, 4).toArray();
// [3, 4, 5]

FAQs

Package last updated on 29 Apr 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