what’s the double arrow (

<< and * are both YAML keys (you can also think of them as operators). And one more key related to your question is &.

In YAML, you can define anchors and later use them. For example,

foo: &myanchor
  key1: "val1"
  key2: "val2"

bar: *myanchor

In this code snippet, & defines an anchor names it myanchor, and *myanchor references that anchor. Now both foo and bar have the same keys and values.

<< is called the YAML merge key. You can compare it to class inheritance in OOP (not so accurate, but can help you understand). See below example.

foo: &myanchor
  key1: "val1"
  key2: "val2"

bar:
  << : *myanchor
  key2: "val2-new"
  key3: "val3"

In this code snippet, we merge keys and values from foo to bar but override the key2 to a new value. And we add a new key-value pair to bar.

Now bar has the following value:

{
  "bar": {
     "key1": "val1",
     "key2": "val2-new",
     "key3": "val3"
   }
}

Leave a Comment