UCE Docs / DValue::each

Signature

void DValue::each(std::function f) const

Parameters

f : callback invoked for each child, or once for a scalar value
return value : none

Iterates a DValue without modifying it. References are dereferenced before iteration.

For map-shaped values, the callback receives each child and its key. List-shaped maps iterate in numeric index order (0, 1, 2, ...); ordinary maps iterate in std::map string-key order. Scalar values invoke the callback once with the current value and an empty key.

Example

DValue user;
user["name"] = "Ada";
user["role"] = "admin";
StringList keys;
user.each([&](const DValue& item, String key) { keys.push_back(key); });
print(join(keys.sort(), ","), "\n");
Output
name,role