# fromable

> transform iterables with map/filter without intermediate values

Latest version **0.2.2** (published 2020-07-25) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2020-07-25 |
| First published | 2020-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 42.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 35 |
| Author | Baron Willeford |
| Maintainers | baron816 |
| Keywords | javascript, typescript |

## Links

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

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2020-07-25
- 0.2.1 — 2020-07-19
- 0.2.0 — 2020-07-04
- 0.1.2 — 2020-07-04
- 0.1.1 — 2020-06-28
- 0.1.0 — 2020-06-28

## README

# Fromable

Fromable allows you take any iterable, tranform it using `.map` and `.filter`, and then output it into a collection, without creating intermediate values.

## Motivation
`arr.filter(isSomething).map(transform);` will allocate two new arrays into memory, when you only want one. Each time you run `.filter` or `.map`, you're creating a whole new array, which will need to be garbage collected.

Additionally, it only operates on arrays. filtering/mapping on Sets/Maps/strings is not [yet](https://github.com/tc39/proposal-iterator-helpers) possible.

## Install

`npm i fromable`

## Usage

`from` will accept any Iterable (array, string, Set, Map, etc).

`into` will accept a number, string, array, Set, Map, or object. It accepts an optional second argument, which will handle custom combinations.

```typescript
import { from } from 'fromable'; // 😆

// chain map and filter on arrays
from([1,2,3,4,5,6])
    .map(val => val + 2)
    .filter(val => val % 2 === 0)
    .map(val => val ** 2)
    .into([]) //=> [16, 36, 64]

// accumulate into a number
from(new Set([1,2,3,4,5,6]))
    .map(val => val + 2)
    .filter(val => val > 4)
    .into(0) //=> 18

// add entries to an object
from("abc")
    .map((val, idx) => [v, i])
    .into({}) //=> { a: 1, b: 2, c: 3}

// zip together multiple iterables
from([1, 2, 3], [4, 5, 6], [7, 8, 9]) 
    .map(([first, second, third]) => first + second + third)
    .into([]) //=> [12, 15, 18]

// use custom combiner
from([1,2,3,4])
    .into(new Queue(), (queue, curr) => queue.enqueue(curr)) //=> Queue <1, 2, 3, 4>
```

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