oωo (owo-lib)

oωo (owo-lib)

17M Downloads

Make Components.list utility function use `Collection` instead of `List`

sisby-folk opened this issue · 1 comments

commented

Hey hi there! Quick tiny thing - The list() function could be a little easier to work with if it only required a Collection rather than a List. The implementation only iterates through them, so it shouldn't mind it being any kind of collection

public static <T, C extends Component> FlowLayout list(List<T> data, Consumer<FlowLayout> layoutConfigurator, Function<T, C> componentMaker, boolean vertical) {
var layout = vertical ? Containers.verticalFlow(Sizing.content(), Sizing.content()) : Containers.horizontalFlow(Sizing.content(), Sizing.content());

Stuff like Map.values() returns collections but not lists, and It'd save a bit of extra constructing.

commented

This function requires a List precisely because it makes an ordered list of components. Thus, it's only sensible to also require an ordered collection of items (which we then call a list) as input.

I believe this also encourages actually sorting the incoming data by some meaningful characteristic, which leads to much improved UX - having the same list of items be potentially in a different order every time I see it is not a great user experience.

While I can appreciate there may be cases where one has a collection with deterministic iteration order (like the values of a linked map) that is not a list, I don't think that warrants weakening this function's contract

Cheers