-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking if this still falls into There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. on another side There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
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'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
}); | ||
}); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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)