Apply `func` to each entry in `structure` and return a new structure.
(
func: Callable[[_T], _U], *structure: NestedStructure[_T]
)
| 252 | |
| 253 | |
| 254 | def map_structure( |
| 255 | func: Callable[[_T], _U], *structure: NestedStructure[_T] |
| 256 | ) -> NestedStructure[_U]: |
| 257 | """ |
| 258 | Apply `func` to each entry in `structure` and return a new structure. |
| 259 | """ |
| 260 | flat_structure = [flatten(s) for s in structure] |
| 261 | entries = zip(*flat_structure) |
| 262 | return pack_sequence_as(structure[0], [func(*x) for x in entries]) |
| 263 | |
| 264 | |
| 265 | def hold_mutable_vars(structure): |
no test coverage detected