# polyethylene

> Functional programming for iterables and async iterables

Latest version **2.5.4** (published 2024-12-30) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 40/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.5.4 |
| Published | 2024-12-30 |
| First published | 2018-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 909.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Daniel Escoz |
| Maintainers | darkhogg |

## Links

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

## Recent versions

- 2.5.4 (latest) — 2024-12-30
- 2.0.0-4 (next) — 2022-01-24
- 2.5.3 — 2024-12-02
- 2.5.2 — 2024-01-01
- 2.5.1 — 2023-12-31
- 2.5.0 — 2023-12-31
- 2.4.0 — 2023-07-04
- 2.3.0 — 2023-03-16
- 2.2.0 — 2023-01-05
- 2.1.1 — 2022-05-05
- 2.1.0 — 2022-05-05
- 2.0.1 — 2022-03-26
- 2.0.0 — 2022-03-25
- 2.0.0-3 — 2021-12-23
- 2.0.0-2 — 2021-12-23
- … 9 more at https://npm.io/package/polyethylene/versions

## README

# Polyethylene

Polyethylene is a wrapping layer around iterators and async iterators that lets you chain
functional operators in a similar way you do with arrays but without the memory overhead or having
to wait for an asynchronous iteration to end.

[![Version](https://img.shields.io/npm/v/polyethylene.svg)](https://www.npmjs.com/package/polyethylene)
[![Tests](https://img.shields.io/github/actions/workflow/status/darkhogg/polyethylene/test.yaml?branch=main)](https://github.com/Darkhogg/polyethylene/actions/workflows/test.yaml?query=branch%3Amain)
[![](https://img.shields.io/github/license/Darkhogg/polyethylene)][license]


## Basic Usage

The default export of `polyethylene` (named `Poly` throughout the documentation) is the main entry point.
You would typically create an "augmented" iterable object using `Poly.asyncFrom` or `Poly.syncFrom`, then you start
calling _transform methods_ like `.map`, `.filter`, etc. in the returned object, ending with a _leaf method_ like
`.reduce` or `.forEach`.

In this way, polyethylene objects behave very similarly to `Array`s, but they are fundamentally different because they
don't store their elements anywhere, instead processing them one by one.

The following is a very simple, fictitious example of using polyethylene:


```typescript
import Poly from 'polyethylene';
import {findUsers, findUserPosts} from 'some-api-lib'

// Print the first 10 posts of each user
await Poly.asyncFrom(findUsers())
  .flatMap(user => Poly.asyncFrom(findUserPosts(user)).take(10))
  .forEach(post => console.log(post));
```

### CommonJS

This package is designed as an ECMAScript Module from the get go, but since 2.1.0 a CommonJS version is provided.

All named exports are supported, but the default export must be accessed via the `default` or `Poly` exports:

```javascript
const Poly = require('polyethylene').default
```
```javascript
const {Poly} = require('polyethylene')
```


## Full Documentation

See the [API Documentation](./docs/polyethylene.md).

## License

Polyethylene is released under the [MIT License][license]

  [license]: ./LICENSE

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