# iter-fun

> Fun with Iterables

Latest version **0.2.0** (published 2021-11-15) · CC0-1.0 license · 0 weekly downloads

## Install

```sh
npm install iter-fun
pnpm add iter-fun
yarn add iter-fun
bun add iter-fun
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2021-11-15 |
| First published | 2021-11-03 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Daniel J. Dufour |
| Maintainers | danieljdufour |
| Keywords | array, iter, iterable, iterate, iterator |

## Links

- npm: https://www.npmjs.com/package/iter-fun
- Repository: https://github.com/DanielJDufour/iter-fun
- Homepage: https://github.com/DanielJDufour/iter-fun#readme
- Issues: https://github.com/DanielJDufour/iter-fun/issues
- npm.io page: https://npm.io/package/iter-fun

## Recent versions

- 0.2.0 (latest) — 2021-11-15
- 0.1.2 — 2021-11-05
- 0.1.1 — 2021-11-03
- 0.1.0 — 2021-11-03
- 0.0.1 — 2021-11-03

## README

# iter-fun
Fun with Iterables

# install
```bash
npm install iter-fun
```

# usage
```js
import { getOrCreateIterator } from "iter-fun";
// if the object has an iterator, return it
// if not, create one from the object
const iter = getOrCreateIterator(obj);

import { isArray } from "iter-fun";
isArray([1, 2, 3]); // true

import { isIterator } from "iter-fun";
isIterator([1, 2, 3][Symbol.iterator]()); // true

import { hasNext } from "iter-fun";
hasNext({ next: () => {...} }); // true

import { hasIterator } from "iter-fun";
hasIterator({ "@@iterator": ... }); // true

import { hasSymbolIterator } from "iter-fun";
hasSymbolIterator(Array); // true

import { getIterator } from "iter-fun";
const iter = getIterator([1, 2]);
iter.next(); // { value: 1, done: false }
iter.next(); // { value: 2, done: false }
iter.next() // { done: true }

import { createIterator } from "iter-fun";
// obj must have a length property
// and index-addressable data like obj[123]
const iter = createIterator(obj);

import { addSymbolIterator } from "iter-fun";
const obj = { next: () => {...} };
addSymbolIterator(obj);
// modifies the object in-place adding a [Symbol.iterator] key

import { addSymbolIteratorFallback } from "iter-fun";
const obj = { next: () => {...} };
addSymbolIteratorFallback(obj);
// modifies the object in-place adding a "@@iterator" string key
// helpful if you are running in an old browser

import { wrapNextFunction } from "iter-fun";
const next = () => { ... };
const iter = wrapNextFunction(next);
// converts a next function into a fully functioning iterable

import { zip } from "iter-fun";
const zeros = [0, 0, 0, ...];
const twos = [2, 2, 2, ...];
const sixties = [60, 60, 60, ...];
const iters = [zeros, twos, sixties];
const zipped = zip(iters);
zipped.next();
// { done: false, value: [0, 2, 60] }
```

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