Let's say I want to get the first item in an array, but i want to make sure that the array is empty first. you can do it in these two ways
if (isNonEmpty(arr)) {
const first = arr[0];
}
or
if (!isNonEmpty(arr)) {
return;
}
const first = arr[0];
I would normally prefer the second option as it would allow for less nesting.
The problem is that !isNonEmpty(arr) doesn't really look good and is kinda weird to read (not is not empty). Here it would be much easier to just use isEmpty(arr). This would also read nicely if you want to use !isEmpty(arr) and still feels intuitive.
Let's say I want to get the first item in an array, but i want to make sure that the array is empty first. you can do it in these two ways
or
I would normally prefer the second option as it would allow for less nesting.
The problem is that
!isNonEmpty(arr)doesn't really look good and is kinda weird to read (not is not empty). Here it would be much easier to just useisEmpty(arr). This would also read nicely if you want to use!isEmpty(arr)and still feels intuitive.