Open josh- opened 6 months ago
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.
The docs for
A.take
state:https://github.com/mobily/ts-belt/blob/c825d9709de1e5d15b1b362429e0cee56c96c516/src/Array/index.ts#L147
however if
n
is greater than the length of the array, the whole array is returned instead of an empty array.for example:
logs
[ 1, 2, 3 ]
whereas it should log[]
.when using a negative
n
this does correctly print out an empty array.for example:
logs
[]
.