Skip to content

Commit

Permalink
either (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
flintinatux committed Nov 27, 2018
1 parent 6264927 commit ba09bc8
Show file tree
Hide file tree
Showing 4 changed files with 29 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.53%20kB-blue.svg" alt="gzip-size" style="max-width:100%;"></a>
<a href="#"><img src="https://img.shields.io/badge/gzip--size-1.55%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 @@ -86,6 +86,7 @@ If you've lived with FP long enough, you are likely familiar with most of the fu
| `defaultTo` | `a -> a -> a` |
| `dissoc` | `k -> { k: v } -> { k: v }` |
| `dissocPath` | `[k] -> { k: v } -> { k: v }` |
| `either` | `(a -> Boolean) -> (a -> Boolean) -> (a -> Boolean)` |
| `evolve` | `{ k: (v -> v) } -> { k: v } -> { k: v }` |
| `filter` | `(a -> Boolean) -> [a] -> [a]` |
| `find` | `(a -> Boolean) -> [a] -> a` |
Expand Down
6 changes: 6 additions & 0 deletions src.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ const dissocPath = curry(([ head, ...tail ], obj) =>
dissoc(head, obj)
)

// either :: (a -> Boolean) -> (a -> Boolean) -> (a -> Boolean)
const either = curry((f, g, x) =>
f(x) || g(x)
)

// evolve :: { k: (v -> v) } -> { k: v } -> { k: v }
const evolve = curry((xfrms, obj) => {
return mapObj(_xfrm(xfrms), obj)
Expand Down Expand Up @@ -429,6 +434,7 @@ _assign(exports, {
defaultTo,
dissoc,
dissocPath,
either,
evolve,
filter,
find,
Expand Down
20 changes: 20 additions & 0 deletions test/either.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { expect } = require('chai')

const { either, prop } = require('..')

describe('either', () => {
const f = prop('f')
const g = prop('g')

const obj = { g: 'h' }

it('wraps two functions in an || operation', () =>
expect(either(f, g, obj)).to.equal('h')
)

it('is curried', () => {
expect(either(f)(g, obj)).to.equal('h')
expect(either(f, g)(obj)).to.equal('h')
expect(either(f)(g)(obj)).to.equal('h')
})
})
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 ba09bc8

Please sign in to comment.