linear-base icon indicating copy to clipboard operation
linear-base copied to clipboard

Add safeIndex for Pull Arrays

Open kephas opened this issue 2 years ago • 4 comments

I wonder if there was a reason behind the absence of a Array a %1 -> Int -> (Maybe a, Array a) function.

kephas avatar Nov 28 '23 16:11 kephas

As mentioned in #471, index isn't safe and hence neither is safeIndex. There may be a save by changing it to return Maybe (a, Array a), where the second array has the element removed (and everything after it shifted forward by one).

b-mehta avatar Nov 28 '23 17:11 b-mehta

As index isn't safe in terms of linearity, the goal was just to have a function that wouldn't fail with an exception.

kephas avatar Nov 28 '23 19:11 kephas

Hi @kephas , thanks for your PR.

Is this safeIndex (or just index) something that you have some need for. Because in the discussion on #471 , we seem to be leaning rather on the side of removing this function altogether. So I guess, what I'm asking is: do you have opposing arguments that'd help us take an informed decision?

aspiwack avatar Nov 29 '23 13:11 aspiwack

I just started to look at index because it's used in the vecfilter example of Data.Array.Polarized and I started from there in my experiments with Pull arrays. I would have felt at home with any API that doesn't throw exceptions.

kephas avatar Dec 01 '23 14:12 kephas

@kephas Thanks for pointing out that index is used in the example. We have removed index now and also updated the example. Given these changes, are you OK with closing this PR?

sjoerdvisscher avatar Apr 09 '24 08:04 sjoerdvisscher

I had wondered why there isn't a uncons, the API is so much better with it! The example is really clearer too.

kephas avatar Apr 09 '24 22:04 kephas