Airstream icon indicating copy to clipboard operation
Airstream copied to clipboard

Add splitByIndex

Open ajaychandran opened this issue 3 years ago • 3 comments

Airstream provides a split operator that can used to improve the rendering performance of a list of elements. However this only works if the element can be mapped to a unique key (or in other words, the list has no duplicates).

A list with duplicates could be handled by using the index of an element as a key. WDYT?

ajaychandran avatar Apr 20 '21 12:04 ajaychandran

Hm... seems like splitByIndex can be DIY-d with something like observable.map(_.zipWithIndex).split(_._2)(...)?

What are you rendering that you care to reuse elements by index – logs or something? There's also children.command in Laminar for special cases. Its use case is quite limited, but really works well when that's what you need.

raquo avatar Apr 21 '21 08:04 raquo

I have Signal containing a list of non-unique elements that each map to an image. Using observable.map(_.zipWithIndex).split(_._2)(...) works but requires creating an intermediate list.

ajaychandran avatar Apr 21 '21 09:04 ajaychandran

I'd like to hear if anyone else wants this. Adapting the current implementation of split would complicate the code used for all existing usages of split. Alternatively, writing a separate implementation that's mostly redundant would not be very elegant (double that since a separate impl is required for streams and signals). So... I'll wait for more demand for this.

raquo avatar May 05 '21 00:05 raquo