dartz
dartz copied to clipboard
What is the 'functional way' to insert values in ilist, ivector?
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...
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.