lucaong / immutable

Thread-safe, persistent, immutable collections for the Crystal language
MIT License
203 stars 11 forks source link

Is there a way to get a new vector with one item removed on a certain index? #10

Open Frederik-Baetens opened 5 years ago

Frederik-Baetens commented 5 years ago

I would like something like delete_at in crystal's arrays.

lucaong commented 5 years ago

Sorry for the delay, I completely missed this issue.

In principle, delete_at could be implemented, but as far as I see not very efficiently: I think in general there is no better way than concatenating the part before and after the element to delete, which would be costly for big collections. If that is a common operation, probably modeling the problem with a Map would be better.

I will think about this though, if there is an efficient way to implement it.

wishfoundry commented 5 years ago

RRB tries are a later iteration from bagwell, and are quite efficient at joining 2 lists. I believe funkia/list has some code you might be able to read easily to grasp the concepts

lucaong commented 5 years ago

Interesting! I will delve through it, thanks for the suggestion!

Frederik-Baetens commented 5 years ago

Scala's vector also allows this with the patch functiion, looking at that might be helpful too