# `YAML.Merge`
[🔗](https://github.com/sruplex/yaml/blob/main/lib/yaml/merge.ex#L1)

Resolves YAML merge keys (<<) in AST documents.

## Example

Input YAML:
```yaml
description: "This is line one\nThis is line two\n"
defaults:
  retries: 3
  timeout: 30
  created_at: "2025-01-01T00:00:00Z"
service_a:
  <<: *defaults
  timeout: 60
```

Input AST:
```elixir
[
  %YAML.AST.Document{
    root: %YAML.AST.Mapping{
      pairs: [
        {%YAML.AST.Scalar{value: "description", ...},
         %YAML.AST.Scalar{value: "This is line one\nThis is line two\n", ...}},
        {%YAML.AST.Scalar{value: "defaults", ...},
         %YAML.AST.Mapping{
           pairs: [
             {%YAML.AST.Scalar{value: "retries", ...}, %YAML.AST.Scalar{value: 3, ...}},
             {%YAML.AST.Scalar{value: "timeout", ...}, %YAML.AST.Scalar{value: 30, ...}},
             {%YAML.AST.Scalar{value: "created_at", ...}, %YAML.AST.Scalar{value: "2025-01-01T00:00:00Z", ...}}
           ], ...
         }},
        {%YAML.AST.Scalar{value: "service_a", ...},
         %YAML.AST.Mapping{
           pairs: [
             {%YAML.AST.Scalar{value: "<<", ...}, %YAML.AST.Mapping{pairs: [...], ...}},
             {%YAML.AST.Scalar{value: "timeout", ...}, %YAML.AST.Scalar{value: 60, ...}}
           ], ...
         }}
      ], ...
    }
  }
]
```

Output AST (after merge):
```elixir
[
  %YAML.AST.Document{
    root: %YAML.AST.Mapping{
      pairs: [
        {%YAML.AST.Scalar{value: "description", ...},
         %YAML.AST.Scalar{value: "This is line one\nThis is line two\n", ...}},
        {%YAML.AST.Scalar{value: "defaults", ...},
         %YAML.AST.Mapping{
           pairs: [
             {%YAML.AST.Scalar{value: "retries", ...}, %YAML.AST.Scalar{value: 3, ...}},
             {%YAML.AST.Scalar{value: "timeout", ...}, %YAML.AST.Scalar{value: 30, ...}},
             {%YAML.AST.Scalar{value: "created_at", ...}, %YAML.AST.Scalar{value: "2025-01-01T00:00:00Z", ...}}
           ], ...
         }},
        {%YAML.AST.Scalar{value: "service_a", ...},
         %YAML.AST.Mapping{
           pairs: [
             # << key removed, pairs merged:
             {%YAML.AST.Scalar{value: "retries", ...}, %YAML.AST.Scalar{value: 3, ...}},
             {%YAML.AST.Scalar{value: "created_at", ...}, %YAML.AST.Scalar{value: "2025-01-01T00:00:00Z", ...}},
             {%YAML.AST.Scalar{value: "timeout", ...}, %YAML.AST.Scalar{value: 60, ...}}  # overridden value
           ], ...
         }}
      ], ...
    }
  }
]
```

Notice:
- The `<<` key is removed from service_a
- `retries` and `created_at` are merged from defaults
- `timeout` is overridden to 60 (local value wins)

# `apply`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
