# @gen-x/list

> list handling for gen-x

Latest version **2.0.0** (published 2021-11-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @gen-x/list
pnpm add @gen-x/list
yarn add @gen-x/list
bun add @gen-x/list
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-11-21 |
| First published | 2020-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 27 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | johngeorgewright |

## Links

- npm: https://www.npmjs.com/package/@gen-x/list
- Homepage: https://github.com/johngeorgewright/gen-x#readme
- Issues: https://github.com/johngeorgewright/gen-x/issues
- npm.io page: https://npm.io/package/@gen-x/list

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) 2.3.1

## Recent versions

- 2.0.0 (latest) — 2021-11-21
- 1.0.2 — 2021-10-10
- 1.0.1 — 2021-02-25
- 1.0.0 — 2020-10-28
- 0.0.0 — 2020-10-28

## README

# @gen-x/list

> List handling for gen-x

When GenX handles anything iterable, it will yield each individual item through the pipeline. Here's an example when returning or yielding an array from an operator in the pipeline:

```typescript
import genX from '@gen-x/core'

const iterate = genX(() => [1, 2, 3, 4])

for await (const x of iterate()) {
  console.info(x)
}

// 1
// 2
// 3
// 4
```

If you want to return a collection of items without it being iterated on, you could use a `List`, which is a simple, non-iterable, array structure.

```typescript
import genX from '@gen-x/core'
import * as list from '@gen-x/list'

const iterate = genX(() => list.create(1, 2, 3, 4))

for await (const x of iterate()) {
  console.info(x)
}

// {Symbol(list items): [1, 2, 3, 4]}
```

There are also utilities for traversing/manipulating a list, which are named the same as Array.prototype functions

- `concat`
- `every`
- `filter`
- `find`
- `findIndex`
- `forEach`
- `from`
- `includes`
- `indexOf`
- `join`
- `keys`
- `lastIndexOf`
- `map`
- `pop`
- `push`
- `reduce`
- `reverse`
- `shift`
- `slice`
- `some`
- `sort`
- `splice`
- `unshift`

Apart from being non-iterable, there are a couple of main differences:

1. Lists are immutable. All functions will return a new list.
1. `forEach`'s iteration can be stopped by returning `list.Break`

   ```typescript
   import * as list from '@gen-x/list'
   const l = list.create(1, 2, 3, 4)

   list.forEach(l, (x) => {
     if (x >= 3) {
       return list.Break
     }
     console.info(`${x} is less than 3`)
   })

   // 1 is less than 3
   // 2 is less than 3
   ```

1. There is a `list.toArray()` function which will return the list as an array
1. You'll need to use the `list.get()` function to access a property by index:
   ```typescript
   import * as list from '@gen-x/list'
   const l = list.create(1, 2, 3, 4)
   console.info(list.get(l, 1))
   // 2
   ```

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