Interface ValueMerger<O extends @Nullable Object,I extends @Nullable Object>

Type Parameters:
O - the outer (parent) signal value type
I - the inner (mapped) signal value type
All Superinterfaces:
Serializable
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ValueMerger<O extends @Nullable Object,I extends @Nullable Object> extends Serializable
Creates a new outer value by merging a new inner value with the old outer value. Used with the ValueSignal.updater(ValueMerger) helper method to create write callbacks for immutable value patterns.

This interface is used with immutable value patterns where changing the inner value requires creating a new outer value instance.

Example usage with a record:

 record Todo(String task, boolean done) {
     Todo withTask(String task) {
         return new Todo(task, this.done);
     }

     Todo withDone(boolean done) {
         return new Todo(this.task, done);
     }
 }

 ValueSignal<Todo> todoSignal = new ValueSignal<>(
         new Todo("Buy groceries", false));
 textField.bindValue(todoSignal.map(Todo::task),
         todoSignal.updater(Todo::withTask));
 checkbox.bindValue(todoSignal.map(Todo::done),
         todoSignal.updater(Todo::withDone));
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    merge(O outerValue, I newInnerValue)
    Creates a new outer value by merging the new inner value with the old outer value.
  • Method Details

    • merge

      O merge(O outerValue, I newInnerValue)
      Creates a new outer value by merging the new inner value with the old outer value.
      Parameters:
      outerValue - the current outer signal value
      newInnerValue - the new inner value to merge
      Returns:
      the new outer value