Decompose monolithic readme into docs/ directory structure
This commit is contained in:
36
docs/values/diff-patch.md
Normal file
36
docs/values/diff-patch.md
Normal file
@@ -0,0 +1,36 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | [Types](../types/) | **Values** | [Syntax](../syntax/) | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# Diff / Patch
|
||||
|
||||
## Diff
|
||||
|
||||
Use the Diff function to generate a sequence of edits that will transform one value into another.
|
||||
|
||||
```typescript
|
||||
const E = Value.Diff(
|
||||
// const E = [
|
||||
{ x: 1, y: 2, z: 3 }, // { type: 'update', path: '/y', value: 4 },
|
||||
{ y: 4, z: 5, w: 6 } // { type: 'update', path: '/z', value: 5 },
|
||||
); // { type: 'insert', path: '/w', value: 6 },
|
||||
// { type: 'delete', path: '/x' }
|
||||
// ]
|
||||
```
|
||||
|
||||
## Patch
|
||||
|
||||
Use the Patch function to apply a sequence of edits.
|
||||
|
||||
```typescript
|
||||
const A = { x: 1, y: 2 };
|
||||
|
||||
const B = { x: 3 };
|
||||
|
||||
const E = Value.Diff(A, B); // const E = [
|
||||
// { type: 'update', path: '/x', value: 3 },
|
||||
// { type: 'delete', path: '/y' }
|
||||
// ]
|
||||
|
||||
const C = Value.Patch<typeof B>(A, E); // const C = { x: 3 }
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
Reference in New Issue
Block a user