27 lines
1004 B
Plaintext
27 lines
1004 B
Plaintext
:title
|
|
dv_group_by
|
|
|
|
:sig
|
|
DValue dv_group_by(DValue tree, function<String (DValue, String)> f)
|
|
|
|
:see
|
|
StringList
|
|
0_DValue
|
|
filter
|
|
|
|
:content
|
|
Groups children into list-like buckets by the string returned from f.
|
|
|
|
These helpers keep common data-shaping code close to render code, routers, and configuration trees. They are useful for route lists, navigation items, cards, and records that need simple transformations before rendering.
|
|
|
|
```cpp
|
|
DValue by_section = dv_group_by(menu, [](DValue item, String key) { return(item["section"].to_string()); });
|
|
```
|
|
|
|
Prefer these helpers over open-coded loops when the transformation itself is the important part of the code. Use an explicit loop when mutation, error handling, or side effects are the main concern.
|
|
|
|
## Related Concepts
|
|
|
|
- JavaScript / React: `Array.map`, `Array.filter`, `Array.find`, object `pick`/`omit`, and grouping route or navigation records before rendering.
|
|
- PHP: `array_map`, `array_filter`, `array_unique`, and associative array projection.
|