index by
index items into a dict
(list xs, function f) -> any
Returns a dict that contains all values from xs. Each x in xs is indexed by key 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 string, or a value that can be cast to string.
In case f(x) returns the same key for multiple x, only one of such x will be indexed in the returned dict.
In such cases it is undefined which x is preserved in the returned dict.
In case f(x) returns nil 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 index |
f |
function |
A function of the form (any x, any i) -> string that returns the index for source item x at source index i. |