Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement nand #952

Merged
merged 2 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,12 @@ declare namespace RamdaAdjunct {
*/
neither(firstPredicate: Function, secondPredicate: Function): Function;

/**
* Returns true if both arguments are falsy; false otherwise.
*/
nand(a: any, b: any): Boolean;
nand(a: any): (b: any) => Boolean;

/**
* Takes a list of predicates and returns a predicate that returns true for a given list of
* arguments if one or more of the provided predicates is not satisfied by those arguments.
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export { default as inRange } from './inRange';
export { default as isNotEmpty } from './isNotEmpty';
export { default as defaultWhen } from './defaultWhen';
export { default as notBoth } from './notBoth';
export { default as nand } from './nand';
export { default as neither } from './neither';
export { default as notAllPass } from './notAllPass';
export { default as nonePass } from './nonePass';
Expand Down
27 changes: 27 additions & 0 deletions src/nand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { and, complement } from 'ramda';

/**
* Returns true if both arguments are falsy; false otherwise.
*
* @func nand
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/2.19.0|v2.19.0}
* @category Logic
* @sig a -> b -> Boolean
* @param {Boolean} a
* @param {Boolean} b
* @return {Boolean} true if both arguments are false
* @example
*
* RA.nand(true, true); //=> false
* RA.nand(false, true); //=> true
* RA.nand(true, false); //=> true
* RA.nand(false, false); //=> true
* RA.nand(1.0, 1.0); //=> false
* RA.nand(1.0, 0); //=> true
* RA.nand(0, 1.0); //=> true
* RA.nand(0, 0); //=> true
*/
const nand = complement(and); // eslint-disable-line ramda/complement-simplification

export default nand;
38 changes: 38 additions & 0 deletions test/nand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import eq from './shared/eq';
import * as RA from '../src';

describe('RA.nand', function() {
it('should work on booleans', function() {
eq(RA.nand(true, true), false);
eq(RA.nand(false, true), true);
eq(RA.nand(true, false), true);
eq(RA.nand(false, false), true);
});

it('should work on numbers', function() {
eq(RA.nand(1.0, 1.0), false);
eq(RA.nand(0.0, 1.0), true);
eq(RA.nand(1.0, 0.0), true);
eq(RA.nand(0.0, 0.0), true);
});

it('should work on a combination of things', function() {
eq(RA.nand(true, 1.0), false);
eq(RA.nand(null, true), true);
eq(RA.nand(1.0, undefined), true);
eq(RA.nand(0.0, false), true);
eq(RA.nand(null, null), true);
eq(RA.nand(null, undefined), true);
});

it('should support currying', function() {
eq(RA.nand(true, true), false);
eq(RA.nand(true)(true), false);
eq(RA.nand(false, true), true);
eq(RA.nand(false)(true), true);
eq(RA.nand(true, false), true);
eq(RA.nand(true)(false), true);
eq(RA.nand(false, false), true);
eq(RA.nand(false)(false), true);
});
});