Map a function over all of the scalar values of a grouping, maintaining the grouping structure :param fn: Single-argument function that accepts and returns scalar grouping values :param grouping: The grouping to map the function over :return: A new grouping with the same struct
(fn, grouping)
| 124 | |
| 125 | |
| 126 | def map_grouping(fn, grouping): |
| 127 | """ |
| 128 | Map a function over all of the scalar values of a grouping, maintaining the |
| 129 | grouping structure |
| 130 | |
| 131 | :param fn: Single-argument function that accepts and returns scalar grouping values |
| 132 | :param grouping: The grouping to map the function over |
| 133 | :return: A new grouping with the same structure as input grouping with scalar |
| 134 | values updated by the input function. |
| 135 | """ |
| 136 | if isinstance(grouping, (tuple, list)): |
| 137 | return [map_grouping(fn, g) for g in grouping] |
| 138 | |
| 139 | if isinstance(grouping, dict): |
| 140 | return AttributeDict({k: map_grouping(fn, g) for k, g in grouping.items()}) |
| 141 | |
| 142 | return fn(grouping) |
| 143 | |
| 144 | |
| 145 | def make_grouping_by_key(schema, source, default=None): |
searching dependent graphs…