Node.opIndex

Get the element at specified index.

If the node is a sequence, index must be integral.

More...
struct Node
ref inout return scope @safe
inout(Node)
opIndex
(
T
)
()

Return Value

Type: inout(Node)

Value corresponding to the index.

Detailed Description

If the node is a mapping, return the value corresponding to the first key equal to index. containsKey() can be used to determine if a mapping has a specific key.

To get element at a null index, use YAMLNull for index.

Throws

NodeException if the index could not be found, non-integral index is used with a sequence or the node is not a collection.

Examples

Node narray = Node([11, 12, 13, 14]);
Node nmap   = Node(["11", "12", "13", "14"], [11, 12, 13, 14]);

assert(narray[0].as!int == 11);
assert(null !is collectException(narray[42]));
assert(nmap["11"].as!int == 11);
assert(nmap["14"].as!int == 14);

Meta