-
-
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 isNonEmptyArray #289
Merged
+59
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
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. 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
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. 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); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@char0n I think yes, there is no way we can express that array is non-empty in types
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.
Wouldn't be better to use
boolean
instead ?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.
Look
https://www.typescriptlang.org/play/index.html#src=declare%20function%20isNonEmptyArray(val%3A%20any)%3A%20val%20is%20Array%3Cany%3E%3B%0D%0A%0D%0Afunction%20createName(name%3A%20any)%20%7B%0D%0A%20%20%20%20if%20(isNonEmptyArray(name))%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20name.join()%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20else%20%7B%0D%0A%20%20%20%20%20%20%20%20return%20name.join(%22%20%22)%3B%0D%0A%20%20%20%20%7D%0D%0A%7D
when
isNonEmptyArray
returnsfalse
array methods still can be applied onname
so
val is Array<any>
if fine )