Revision 1882
Added by Aaron Marcuse-Kubitza over 12 years ago
collection.py | ||
---|---|---|
1 | 1 |
# Data structures |
2 | 2 |
|
3 |
import iters |
|
4 |
|
|
3 | 5 |
def rmap(func, value): |
4 | 6 |
'''Recursively applies func to all members of value''' |
5 |
if isinstance(value, list): return map(func, list_) |
|
6 |
elif isinstance(value, dict): |
|
7 |
return dict(((k, func(v)) for k, v in value.iteritems())) |
|
7 |
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) |
|
8 | 11 |
else: return func(value) |
Also available in: Unified diff
collection.py: rmap(): Fixed bugs: Made it recursive. Use iters.is_iterable() instead of isinstance(value, list) to work on all iterables. Use value and not nonexistent var list_.