mobily/ts-belt

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

Opened this issue · 2 comments

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 [].

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

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.