root/lib/collection.py @ 1882
1 | 1875 | aaronmk | # Data structures
|
---|---|---|---|
2 | |||
3 | 1882 | aaronmk | import iters |
4 | |||
5 | 1875 | aaronmk | def rmap(func, value): |
6 | '''Recursively applies func to all members of value'''
|
||
7 | 1882 | aaronmk | rmap_ = lambda v: rmap(func, v) |
8 | if isinstance(value, dict): |
||
9 | return dict(((k, rmap_(v)) for k, v in value.iteritems())) |
||
10 | elif iters.is_iterable(value): return map(rmap_, value) |
||
11 | 1875 | aaronmk | else: return func(value) |