Skip to content

Commit

Permalink
find
Browse files Browse the repository at this point in the history
  • Loading branch information
flintinatux committed Sep 18, 2018
1 parent df77025 commit 910beba
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<p align="center">
<a href="https://www.npmjs.com/package/tinyfunk"><img src="https://img.shields.io/npm/v/tinyfunk.svg" alt="npm version" style="max-width:100%;"></a>
<a href="https://www.npmjs.com/package/tinyfunk"><img src="https://img.shields.io/npm/dm/tinyfunk.svg" alt="npm downloads" style="max-width:100%;"></a>
<a href="#"><img src="https://img.shields.io/badge/gzip--size-1.43%20kB-blue.svg" alt="gzip-size" style="max-width:100%;"></a>
<a href="#"><img src="https://img.shields.io/badge/gzip--size-1.44%20kB-blue.svg" alt="gzip-size" style="max-width:100%;"></a>
<br />
<a href="https://travis-ci.org/flintinatux/tinyfunk"><img src="https://travis-ci.org/flintinatux/tinyfunk.svg?branch=master" alt="Build Status" style="max-width:100%;"></a>
<a href="https://coveralls.io/github/flintinatux/tinyfunk?branch=master"><img src="https://coveralls.io/repos/github/flintinatux/tinyfunk/badge.svg?branch=master" alt="Coverage Status" style="max-width:100%;"></a>
Expand Down Expand Up @@ -89,6 +89,7 @@ If you've lived with FP long enough, you are likely familiar with most of the fu
| `dissocPath` | `[k] -> { k: v } -> { k: v }` |
| `evolve` | `{ k: (v -> v) } -> { k: v } -> { k: v }` |
| `filter` | `(a -> Boolean) -> [a] -> [a]` |
| `find` | `(a -> Boolean) -> [a] -> a` |
| `flip` | `(a -> b -> c) -> (b -> a -> c)` |
| `head` | `[a] -> a` |
| `identity` | `a -> a` |
Expand Down
6 changes: 6 additions & 0 deletions src.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ const filter = curry((pred, list) =>
list.filter(pred)
)

// find :: (a -> Boolean) -> [a] -> a
const find = curry((pred, list) =>
list.find(pred)
)

// flip :: (a -> b -> c) -> (b -> a -> c)
const flip = curry((f, x, y) =>
curry(f)(y, x)
Expand Down Expand Up @@ -394,6 +399,7 @@ _assign(exports, {
dissocPath,
evolve,
filter,
find,
flip,
head,
identity,
Expand Down
18 changes: 18 additions & 0 deletions test/find.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { expect } = require('chai')

const { find } = require('..')

describe('find', () => {
const arr = [1, 2, 3, 4]

const gt2 = x =>
x > 2

it('finds an item in a list', () =>
expect(find(gt2, arr)).to.equal(3)
)

it('is curried', () =>
expect(find(gt2)(arr)).to.equal(3)
)
})
2 changes: 1 addition & 1 deletion tinyfunk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 910beba

Please sign in to comment.