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

feat: add isNonEmptyArray #289

Merged
merged 3 commits into from
Jan 19, 2018
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
5 changes: 5 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ declare namespace RamdaAdjunct {
*/
isNotArray(val: any): boolean;

/**
* Checks if input value is a non empty `Array`.
*/
isNonEmptyArray(val: any): val is Array<any>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BjornMelgaard I'm not sure about this. Can you advice ? Does this signature make sense in the context of empty array ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@char0n I think yes, there is no way we can express that array is non-empty in types

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to use boolean instead ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/**
* Checks if input value is complement of `Boolean`.
*/
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export { default as isNotNull } from './isNotNull';
export { default as isNotNil } from './isNotNil';
export { default as isArray } from './isArray';
export { default as isNotArray } from './isNotArray';
export { default as isNonEmptyArray } from './isNonEmptyArray';
export { default as isBoolean } from './isBoolean';
export { default as isNotBoolean } from './isNotBoolean';
export { default as isNilOrEmpty } from './isNilOrEmpty';
Expand Down
29 changes: 29 additions & 0 deletions src/isNonEmptyArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { both } from 'ramda';

import isNotEmpty from './isNotEmpty';
import isArray from './isArray';

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert one new empty line pls

/**
* Checks if input value is not an empty `Array`.
*
* @func isNonEmptyArray
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/2.4.0|v2.4.0}
* @category Type
* @sig * -> Boolean
* @param {*} val The value to test
* @return {Boolean}
* @see {@link RA.isEmptyArray|isEmptyArray}
* @example
*
* RA.isNonEmptyArray([42]); // => true
* RA.isNonEmptyArray([]); // => false
* RA.isNonEmptyArray({}); // => false
* RA.isNonEmptyArray(null); // => false
* RA.isNonEmptyArray(undefined); // => false
* RA.isNonEmptyArray(42); // => false
* RA.isNonEmptyArray('42'); // => false
*/
const isNonEmptyArray = both(isArray, isNotEmpty);

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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert one new empty line pls


describe('isNonEmptyArray', function () {
it('tests a value to be a non empty `Array`', function () {
eq(RA.isNonEmptyArray([42]), true);
eq(RA.isNonEmptyArray(new Array('content')), true);

eq(RA.isNonEmptyArray([]), false);
eq(RA.isNonEmptyArray(new Array()), false);
eq(RA.isNonEmptyArray(new Array(42)), false);
eq(RA.isNonEmptyArray(Array.prototype), false);
eq(RA.isNonEmptyArray(void 0), false);
eq(RA.isNonEmptyArray({}), false);
eq(RA.isNonEmptyArray(null), false);
eq(RA.isNonEmptyArray(undefined), false);
eq(RA.isNonEmptyArray(42), false);
eq(RA.isNonEmptyArray('Array'), false);
eq(RA.isNonEmptyArray(true), false);
eq(RA.isNonEmptyArray(false), false);
eq(RA.isNonEmptyArray({ __proto__: Array.prototype }), false);
});
});