group deep by
groups items into a nested dict of lists
(list xs, function f) -> any
Returns a nested dict. Each x of xs is collected in a list located at the sequence of keys given by f(x).
If xs is a list:
If f accepts one argument, x is passed.
If f accepts two arguments, x and its index are passed.
If xs is a dict:
If f accepts one argument, each entry’s value is passed.
If f accepts two arguments, each entry’s value and key are passed.
The indexing function f must return a list of strings representing a path of keys to the list where item x should be placed.
The order of items in collecting lists is undefined.
If f returns paths p1 and p2, p2 is longer than p1, and p2 starts with p1, the behavior of group_deep_by is undefined.
In case f(x) returns nil or an empty list, the corresponding x is omitted from the result.
Returns nil if xs is nil.
Throws an error if xs is neither a list nor a dict.
Throws an error if f is nil.
Parameters
| Name | Type | Description |
|---|---|---|
xs |
list or dict | The list or dict of items to group |
f |
function |
A function of the form (any x, any i) -> string that returns the path of keys to the list for source item x at source index i. |