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 isEmptyArray #288

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 @@ -38,6 +38,11 @@ declare namespace RamdaAdjunct {
*/
isArray(val: any): val is Array<any>;

/**
* Checks if input value is an empty `Array`.
*/
isEmptyArray(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.

same as here #289 (comment)


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

import isArray from './isArray';


/**
* Checks if input value is an empty `Array`.
*
* @func isEmptyArray
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/2.4.0|v2.4.0}
* @category Type
Copy link
Owner

Choose a reason for hiding this comment

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

Thinking if this still falls into Type category or is already an Logic. @guillaumearm what's your opinion on this ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be using logic under the hood, but its API and usage put it in Type imho.

Copy link
Owner

Choose a reason for hiding this comment

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

Agree

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In fact, it's a mix of both : Type and Logic

Because an empty array and a non empty array have the same type, it's a very good question to ask.
Is it ok to passing same type to a Type function produce a different result ?

on another side RA.isNotEmpty should be in Logic category like R.isEmpty

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for creating the issue for it. I’ll handle that. Regarding the question whether this is type or logic... I would say we are still in type world. If we look at it throug the lens of category theory let us say we have two new types EmptyArray and NonEmptyArray. Assuming this we cas say that our two new type functions are just checking out the correct types. Logic of the checking becomes only the implementation detail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems correct, Agree ^^

* @sig * -> Boolean
* @param {*} val The value to test
* @return {Boolean}
* @see {@link RA.isNotEmptyArray|isNotEmptyArray}
* @example
*
* RA.isEmptyArray([]); // => true
* RA.isEmptyArray([42]); // => false
* RA.isEmptyArray({}); // => false
* RA.isEmptyArray(null); // => false
* RA.isEmptyArray(undefined); // => false
* RA.isEmptyArray(42); // => false
* RA.isEmptyArray('42'); // => false
*/
const isEmptyArray = both(isArray, isEmpty);

export default isEmptyArray;
22 changes: 22 additions & 0 deletions test/isEmptyArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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.

add one more new line pls


describe('isEmptyArray', function () {
it('tests a value to be an empty `Array`', function () {
eq(RA.isEmptyArray([]), true);
eq(RA.isEmptyArray(new Array()), true);
eq(RA.isEmptyArray(Array.prototype), true);

eq(RA.isEmptyArray([1]), false);
eq(RA.isEmptyArray(void 0), false);
eq(RA.isEmptyArray({}), false);
eq(RA.isEmptyArray(null), false);
eq(RA.isEmptyArray(undefined), false);
eq(RA.isEmptyArray(17), false);
eq(RA.isEmptyArray('Array'), false);
eq(RA.isEmptyArray(true), false);
eq(RA.isEmptyArray(false), false);
eq(RA.isEmptyArray({ __proto__: Array.prototype }), false);
});
});