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

Add isNotNil #2818

Merged
merged 2 commits into from
Jan 22, 2022
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
1 change: 1 addition & 0 deletions source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export { default as invoker } from './invoker.js';
export { default as is } from './is.js';
export { default as isEmpty } from './isEmpty.js';
export { default as isNil } from './isNil.js';
export { default as isNotNil } from './isNotNil.js';
export { default as join } from './join.js';
export { default as juxt } from './juxt.js';
export { default as keys } from './keys.js';
Expand Down
22 changes: 22 additions & 0 deletions source/isNotNil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import isNil from './isNil.js';
import _curry1 from './internal/_curry1.js';


/**
* Checks if the input value is not `null` and not `undefined`.
*
* @func
* @memberOf R
* @category Type
* @sig * -> Boolean
* @param {*} x The value to test.
* @return {Boolean} `true` if `x` is not `undefined` or not `null`, otherwise `false`.
* @example
*
* R.isNotNil(null); //=> false
* R.isNotNil(undefined); //=> false
* R.isNotNil(0); //=> true
* R.isNotNil([]); //=> true
*/
var isNotNil = _curry1(function isNotNil(x) { return !isNil(x); });
customcommander marked this conversation as resolved.
Show resolved Hide resolved
export default isNotNil;
15 changes: 15 additions & 0 deletions test/isNotNil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var R = require('../source');
var eq = require('./shared/eq');

describe('isNotNil', function() {
it('tests a value for `null` or `undefined`', function() {
eq(R.isNotNil(void 0), false);
eq(R.isNotNil(undefined), false);
eq(R.isNotNil(null), false);
eq(R.isNotNil([]), true);
eq(R.isNotNil({}), true);
eq(R.isNotNil(0), true);
eq(R.isNotNil(''), true);
});

});