def data_tree_map(func, data_tree): ''' Map func to every ABITypedData element in the tree. func will receive two args: abi_type, and data ''' def map_to_typed_data(elements): if isinstance(elements, ABITypedData) and elements.abi_type is not None: return ABITypedData(func(*elements)) else: return elements return recursive_map(map_to_typed_data, data_tree)
def data_tree_map(func, data_tree): ''' Map func to every ABITypedData element in the tree. func will receive two args: abi_type, and data ''' def map_to_typed_data(elements): if isinstance(elements, ABITypedData) and elements.abi_type is not None: return ABITypedData(func(*elements)) else: return elements return recursive_map(map_to_typed_data, data_tree)
def recursive(cls, value): return recursive_map(cls._apply_if_mapping, value)
def test_recursive_collection_cycle(): data = [3] data.append(data) with pytest.raises(ValueError): recursive_map(square_int, data)
def test_recursive_collection_apply(): assert recursive_map(square_int, [[3]]) == [[9]]
def recursive(cls, value): return recursive_map(cls._apply_if_mapping, value)