| 1 | /** |
| 2 | * Interfaces for describing changes to a value as patches. A |
| 3 | * `Differ<T, Patch>` compares an old and new value, creates a patch for the |
| 4 | * difference, combines patches in order, and applies a patch to an old value to |
| 5 | * produce an updated value. |
| 6 | * |
| 7 | * @since 4.0.0 |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * Describes how to compute, combine, and apply patches for values of type `T`. |
| 12 | * |
| 13 | * **When to use** |
| 14 | * |
| 15 | * Use to model patch-based updates for a value type when callers need to |
| 16 | * compute a patch from two values, combine patches, and apply a patch later. |
| 17 | * |
| 18 | * **Details** |
| 19 | * |
| 20 | * A `Differ` provides an empty patch, computes the patch between two values, |
| 21 | * combines patches, and applies a patch to an old value to produce an updated |
| 22 | * value. |
| 23 | * |
| 24 | * @category models |
| 25 | * @since 2.0.0 |
| 26 | */ |
| 27 | export interface Differ<in out T, in out Patch> { |
| 28 | readonly empty: Patch |
| 29 | diff(oldValue: T, newValue: T): Patch |
| 30 | combine(first: Patch, second: Patch): Patch |
| 31 | patch(oldValue: T, patch: Patch): T |
| 32 | } |