Repository: char0n/ramda-adjunct
Pull request #952 (2019-06-09 05:34:01)

Implement nand
Tries to solve https://github.com/char0n/ramda-adjunct/issues/237

Note: While committing it, eslint-plugin-ramda had a bug, see https://github.com/ramda/eslint-plugin-ramda/pull/26, so I disabled this specific eslint rule in the configuration. Maybe I'm missing something.

dawehner: I hopefully addressed all your feedback now! Thank you for the super quick response
dawehner: No worries, I totally hear you about opensource projects. Keeping things consistent can be really hard.
dawehner: I've pushed up a change which hopefully addresses all your feedback. I hope rebasing the PRs is okay.

Patch:
diff --git a/src/index.d.ts b/src/index.d.ts
index 4107543080..cd1b19aeaf 100644
--- a/src/index.d.ts
+++ b/src/index.d.ts
@@ -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.
diff --git a/src/index.js b/src/index.js
index c52b999768..ccd5daf472 100644
--- a/src/index.js
+++ b/src/index.js
@@ -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';
diff --git a/src/nand.js b/src/nand.js
new file mode 100644
index 0000000000..61a298912b
--- /dev/null
+++ b/src/nand.js
@@ -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;


Test patch:
diff --git a/test/nand.js b/test/nand.js
new file mode 100644
index 0000000000..1ef3876216
--- /dev/null
+++ b/test/nand.js
@@ -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);
+  });
+});