insertIntoList method
Inserts value
into the list at path
.
index
must be non-negative and no greater than the list's length.
Throws a ArgumentError if the element at the given path is not a
YamlList
or if the path is invalid.
Throws an AliasException if a node on path
is an alias or anchor.
Example:
final doc = YamlEditor('[0, 2]');
doc.insertIntoList([], 1, 1); // [0, 1, 2]
Implementation
void insertIntoList(Iterable<Object?> path, int index, Object? value) {
final valueNode = wrapAsYamlNode(value);
final list = _traverseToList(path, checkAlias: true);
RangeError.checkValueInInterval(index, 0, list.length);
final edit = insertInList(this, list, index, valueNode);
final expected = wrapAsYamlNode(
[...list.nodes]..insert(index, valueNode),
);
_performEdit(edit, path, expected);
}