Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the 'functional way' to insert values in ilist, ivector? #50

Open
ValeriusGC opened this issue Jun 18, 2020 · 1 comment
Open

Comments

@ValeriusGC
Copy link

prepend, append, set looks great but what if I need insert some entity between existing ones? Which way is the elegant FP-way in paradigm of dartz? I grabbed all the tests but had found no example...

@spebbe
Copy link
Owner

spebbe commented Jun 25, 2020

Hi and thanks for your interest!

Sorry for stalling – I was trying to save face by actually adding a couple of utils for this to IList and IVector, but I need to think about it some more :-) The embarrassing truth is that there are some glaring omissions in the APIs at the moment. For now, arbitrary position inserts will in practice mean having to rebuild the respective collections using existing operations such as flatMap/fold/etc...

Due to the nature of IList (singly linked list), arbitrary position inserts are never going to be very efficient, but for IVector it should be possible to achieve a decent level of performance and structure sharing for insertAt/removeAt style operations.

If your use case is "timeline-like", I would recommend using IMap instead, which supports very efficient insertion and removal of items along an x-axis of your choice.

I'll try to add some operations for this, efficient or not, and will keep this ticket open until then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants