# lazily

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

Latest version **2.0.5** (published 2021-10-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install lazily
pnpm add lazily
yarn add lazily
bun add lazily
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.5 |
| Published | 2021-10-23 |
| First published | 2017-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 32.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jeswin Kumar |
| Maintainers | jeswin |

## Links

- npm: https://www.npmjs.com/package/lazily
- Repository: https://github.com/jeswin/lazily
- Homepage: https://github.com/jeswin/lazily#readme
- Issues: https://github.com/jeswin/lazily/issues
- npm.io page: https://npm.io/package/lazily

## Dependencies (1)

- [@types/node](https://npm.io/package/@types/node.md) ^16.11.4

## Recent versions

- 2.0.5 (latest) — 2021-10-23
- 2.0.4 — 2021-08-21
- 2.0.1 — 2021-08-20
- 2.0.0 — 2021-08-19
- 1.0.3 — 2021-04-05
- 1.0.2 — 2021-03-28
- 1.0.1 — 2020-08-13
- 1.0.0 — 2020-05-02
- 0.0.26 — 2018-08-16
- 0.0.24 — 2018-07-24
- 0.0.23 — 2018-07-23
- 0.0.22 — 2018-05-27
- 0.0.21 — 2018-05-27
- 0.0.20 — 2017-12-08
- 0.0.19 — 2017-12-08
- … 17 more at https://npm.io/package/lazily/versions

## README

# lazily

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

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

## Installation
```
npm install lazily
```

## Create a sequence
```javascript
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.

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

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

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

## flatMap(fn)
```javascript
Seq.of([1, 2, 3])
  .flatMap(x => [x*10, x*20])
  .toArray()
// [11, 21, 12, 22, 13, 23]
```

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

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

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

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

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

## short-circuited reduce(fn, initialValue, stopPredicate)
```javascript
Seq.of([1, 2, 3, 4, 5])
  .reduce((acc, x) => acc + x, 0, acc => acc > 6)
// 10
```

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

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

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

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

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

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

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

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

## reverse()
```javascript
Seq.of([1, 2, 3, 4, 5])
  .reverse()
  .toArray();
// [5, 4, 3, 2, 1]
```

## slice(begin, end)
```javascript
Seq.of([1, 2, 3, 4, 5])
  .slice(2, 4)
  .toArray();
// [3, 4, 5]
```

---
_Source: https://npm.io/package/lazily · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
