Details
Description
Rather often we came across the need to bind to a property of a bound object, like...
windowTitleProperty.bind(Bindings.createStringBinding(() -> {switch(x.getY()) case ...}, x);
...which certainly works well but is not very smart to read particularly if "x" is a complex term itself. Often we noted that we therefore refactored "x" into a variable just for the sake of readability, which is not smart.
Therefore we'd like to propose a minor addition to the Bindings API which makes complex mappings of properties much simpler to read, like...
windowTitleProperty.bind(Bindings.map(o -> {switch(x.getY()) case ...}, x);
...which looks mostly the same for "x" being a variable or very short term, but clearly has a huge advantage in readbility once "x" gets a complex term: As the first parameter to "Bindings.map" is a Function<T, U> but not just a Callback<T>, it does provide the resolved term as parameter "o" already, hence preventing the unnecessary and cluttering resolution of "x" within the Callback<T> function!
This makes particularly complex code shorter and more concise, so we would really be happy to find this in a future JavaFX release.
windowTitleProperty.bind(Bindings.createStringBinding(() -> {switch(x.getY()) case ...}, x);
...which certainly works well but is not very smart to read particularly if "x" is a complex term itself. Often we noted that we therefore refactored "x" into a variable just for the sake of readability, which is not smart.
Therefore we'd like to propose a minor addition to the Bindings API which makes complex mappings of properties much simpler to read, like...
windowTitleProperty.bind(Bindings.map(o -> {switch(x.getY()) case ...}, x);
...which looks mostly the same for "x" being a variable or very short term, but clearly has a huge advantage in readbility once "x" gets a complex term: As the first parameter to "Bindings.map" is a Function<T, U> but not just a Callback<T>, it does provide the resolved term as parameter "o" already, hence preventing the unnecessary and cluttering resolution of "x" within the Callback<T> function!
This makes particularly complex code shorter and more concise, so we would really be happy to find this in a future JavaFX release.
Attachments
Issue Links
- relates to
-
JDK-8274771 Map, FlatMap and OrElse fluent bindings for ObservableValue
- Resolved