DEV Community

Discussion on: The case for replacing Array.slice

Collapse
 
michaeljones profile image
Michael Jones

Thanks for the article. I'd agree that I have to check the docs every time for these kind of methods. I agree that drop & take methods more usable.

I'm curious though, as you understand these data structures very well, if you do want to take a middle slice is there any performance penalty in doing two steps instead of one? I guess there must be but perhaps is minor? I'm not sure I can remember a case where I needed to take a middle slice but as I said, just curious.

Collapse
 
robinheghan profile image
Robin Heggelund Hansen

Fun fact: Both in 0.18 and the upcomming 0.19, slice is actually implemented internally as array |> sliceLeft from |> sliceRight to.

So no, no performance change. In fact, since drop and take wouldn't need to convert negative indices to positive indices, it would likely result in a minor performance boost.