# reduce-first

> Return early from reduce

Latest version **2.0.0** (published 2023-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install reduce-first
pnpm add reduce-first
yarn add reduce-first
bun add reduce-first
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2023-01-10 |
| First published | 2020-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Connor White |
| Maintainers | bconnorwhite |
| Keywords | reduce, first, find, search, array, item, items |

## Links

- npm: https://www.npmjs.com/package/reduce-first
- Repository: https://github.com/bconnorwhite/reduce-first
- Homepage: https://connorwhite.org/github/reduce-first
- Issues: https://github.com/bconnorwhite/reduce-first/issues
- npm.io page: https://npm.io/package/reduce-first

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2023-01-10
- 1.0.1 — 2020-09-10
- 1.0.0 — 2020-09-10

## README

<!--BEGIN HEADER-->
<div id="top" align="center">
  <h1>reduce-first</h1>
  <a href="https://npmjs.com/package/reduce-first">
    <img alt="NPM" src="https://img.shields.io/npm/v/reduce-first.svg">
  </a>
  <a href="https://github.com/bconnorwhite/reduce-first">
    <img alt="TypeScript" src="https://img.shields.io/github/languages/top/bconnorwhite/reduce-first.svg">
  </a>
</div>

<br />

<blockquote align="center">Return early from reduce.</blockquote>

<br />

_If I should maintain this repo, please ⭐️_
<a href="https://github.com/bconnorwhite/reduce-first">
  <img align="right" alt="GitHub stars" src="https://img.shields.io/github/stars/bconnorwhite/reduce-first?label=%E2%AD%90%EF%B8%8F&style=social">
</a>

_DM me on [Twitter](https://twitter.com/bconnorwhite) if you have questions or suggestions._
<a href="https://twitter.com/bconnorwhite">
  <img align="right" alt="Twitter" src="https://img.shields.io/twitter/url?label=%40bconnorwhite&style=social&url=https%3A%2F%2Ftwitter.com%2Fbconnorwhite">
</a>

---
<!--END HEADER-->

`Array.prototype.find` returns the element from an array, and `Array.prototype.reduce` allows you to map to antother value. `reduceFirst` combines these to return a transformation of the first item that returns a value.

## Installation

```sh
yarn add reduce-first
```

```sh
npm install reduce-first
```

```sh
pnpm add reduce-first
```

## Usage

```ts
import reduceFirst from "reduce-first";

const list = ["a", "b", "c", "d", "e"];

const result1 = reduceFirst(list, (value, index, arr) => {
  if(value === "c") {
    return `found ${value}`;
  }
});
// result1 === "found c"

const result2 = reduceFirst(list, (value, index, arr) => {
  if(value === "x") {
    return `found ${value}`;
  }
});
// result2 === undefined
```

<!--BEGIN FOOTER-->

<br />

<h2>Dev Dependencies</h2>

- [autorepo](https://www.npmjs.com/package/autorepo): Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.

<br />

<h2 id="license">License <a href="https://opensource.org/licenses/MIT"><img align="right" alt="license" src="https://img.shields.io/npm/l/reduce-first.svg"></a></h2>

[MIT](https://opensource.org/licenses/MIT) - _MIT License_
<!--END FOOTER-->

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