# @iterables/take

> Take a number of elements from an iterable.

Latest version **1.0.1** (published 2017-04-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @iterables/take
pnpm add @iterables/take
yarn add @iterables/take
bun add @iterables/take
```

## 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 | 1.0.1 |
| Published | 2017-04-10 |
| First published | 2017-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Chris Dickinson |
| Maintainers | chrisdickinson |

## Links

- npm: https://www.npmjs.com/package/@iterables/take
- Repository: https://github.com/chrisdickinson/iterables-take
- Homepage: https://github.com/chrisdickinson/iterables-take#readme
- Issues: https://github.com/chrisdickinson/iterables-take/issues
- npm.io page: https://npm.io/package/@iterables/take

## Recent versions

- 1.0.1 (latest) — 2017-04-10

## README

# @iterables/take

Given an iterable, return an iterable for the leading subset of elements.

```javascript
const take = require('@iterables/take')

console.log([...take([1,2,3], 1)]) // [1]

console.log([...take.until([1,2,3], xs => xs % 2 === 0)]) // [1]

console.log([...take.while([1,2,3], xs => xs !== 3)]) // [1, 2]
```

## Installation

```
$ npm install --save @iterables/take
```

## API

### `take(iterable, n = Infinity) -> Iterator<T>`

Lazily take the first `n` elements of `iterable`, where `n` is an integer
defaulting to `Infinity`. The returned iterator is exhausted when `n` is
reached or when `iterable` is exhausted.

### `take.while(iterable, test) -> Iterator<T>`

Lazily take the first `n` elements of `iterable` while `test` returns `true`.
`test` should be a function taking `xs`, `idx`, and `all` and returning
`Boolean`. `xs` will be an element of the iterable, `idx` will be the index,
and `all` will be the original iterable argument. The returned iterator is
exhausted when `test` returns false, or when `iterable` is exhausted.

### `take.until(iterable, test) -> Iterator<T>`

Lazily take the first `n` elements of `iterable` while `test` returns `false`.
`test` should be a function taking `xs`, `idx`, and `all` and returning
`Boolean`. `xs` will be an element of the iterable, `idx` will be the index,
and `all` will be the original iterable argument. The returned iterator is
exhausted when `test` returns true, or when `iterable` is exhausted.

## License

MIT

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