Interface ValueMerger<O,I>

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,I> extends Serializable
Creates a new outer value by merging a new inner value with the old outer value. Used for creating two-way computed signals where changes to the mapped signal propagate back to the parent signal.

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 text, boolean done) {
     Todo withDone(boolean done) {
         return new Todo(this.text, done);
     }
 }

 WritableSignal<Todo> todoSignal = new ValueSignal<>(
         new Todo("Buy milk", false));
 WritableSignal<Boolean> doneSignal = todoSignal.map(Todo::done,
         Todo::withDone);

 doneSignal.set(true); // Updates todoSignal to Todo("Buy milk", true)
 
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, may be null
      newInnerValue - the new inner value to merge, may be null
      Returns:
      the new outer value, may be null