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

A.take does not return empty array when n greater than length of array (as documented) #102

Open
josh- opened this issue Feb 9, 2024 · 2 comments

Comments

@josh-
Copy link

josh- commented Feb 9, 2024

The docs for A.take state:

/** Returns a new array including the first `n` elements of the provided array, or an empty array if `n` is either negative or greater than the length of the provided array. */

however if n is greater than the length of the array, the whole array is returned instead of an empty array.

for example:

console.log(A.take([1, 2, 3], 10));

logs [ 1, 2, 3 ] whereas it should log [].


when using a negative n this does correctly print out an empty array.

for example:

console.log(A.take([1, 2, 3], -10));

logs [].

@JUSTIVE
Copy link

JUSTIVE commented Feb 9, 2024

The current behavior is more natural/usable. As the take function is just an alias for A.slice(0, x), it should take all elements when the index surpasses the array's length. So, I think the documentation should be matched to its behavior. for the strict action for the take action, we already have one: takeExactly

@JUSTIVE
Copy link

JUSTIVE commented Feb 11, 2024

But that's my opinion, If the purpose of the A.take was what the docs said, the code should be changed. But I'm also scared because some of the codes I wrote work based on the current behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants