Live display JavaFX ObservableList or ReactFX LiveList
/**
* An observable analogue of {@code Stream.map}. The output list is updated
* whenever the input list changes.
*/
public static <T, R> ListBinding<R> map(
ObservableList<? extends T> list,
Function<T, ? extends R> mapper
);
I wrote the above JavaFX utility method that creates a live display ObservableList
by updating the display anytime the original list changes. Later I discovered ReactFX and its equivalentLiveList.map
public interface LiveList {
default <F> LiveList<F> map(Function<? super E,? extends F> f);
}
Not wanting to reinvent the wheel again, I am now looking for a map function that returns a list of observables and automatically observes those observables. Basically flatMap
for the entire list. For example, if I had this:
<T, R> ListBinding<R> flatMap(
ObservableList<? extends T> list,
Function<T, ObservableValue<? extends R>> mapper
);
Then I could do this:
ObservableList<Button> buttons;
ObservableList<Integer> widths = flatMap(buttons, Button::widthProperty);
This list widths
will grow and shrink if buttons are added or removed and will update if the width of the buttons changes.
Does such a feature exist in JavaFX or in ReactFX? Or something like that?
source to share
I am not aware of the existing implementation flatMap
for observable lists.
This is however scheduled for ReactFX 2.0, probably with this signature
public interface LiveList {
default <F> LiveList<F> flatMap(Function<? super E,? extends ObservableList<F>> f);
}
which is more general than what you suggest: it maps the item to a list, not just one value.
source to share