diff --git a/lib/util.py b/lib/util.py index 8ab3276..c391953 100644 --- a/lib/util.py +++ b/lib/util.py @@ -8,6 +8,23 @@ try: except ImportError: import numpy.fft as ft +class MethodMappingProxy(): + def __init__(self, *elements): + self.elements = elements + + def __getattr__(self, name): + # Test name exists on all elements + for el in self.elements: + attr = getattr(el, name) + + if not callable(attr): + raise AttributeError("Attribute `{name}` is not callable on `{el}`.") + + def mapping_func(*args, **kwargs): + return [ getattr(el, name)(*args, **kwargs) for el in self.elements ] + + return mapping_func + def sampled_time(sample_rate=1, start=0, end=1, offset=0): return offset + np.arange(start, end, 1/sample_rate)