[Ethereum] A solidity function to accept two mappings and return a single combined map

mappingsoliditystoragestruct

I've been attempting to implement a function to combine two mappings into a single one:

contract Mappulator {
    mapping(address => int256) public BigMap;
    struct mapper { mapping (address => int256) map;}

    function MappingCombiner(mapper map1, mapper map2){ 
        BigMap = map1.map + map2.map;
    }
} 

According to this I must wrap the mappings in structs to be able to pass them to a function. With the above code I get the following error:

Internal type is not allowed for public or external functions.
function MappingCombiner(mapper map1, mapper map2){ 
                         ^---------^

If I add the storage keyword, as suggested here, I get:

Location has to be memory for publicly visible functions (remove the "storage" keyword).    
function MappingCombiner(mapper storage map1, mapper storage map2){ 
                         ^-----------------^

The compiler is not getting as far as BigMap = map1.map + map2.map; for me to assess if that is valid. I'm assuming not because, to combine them, both maps would have to be iterated over, which is not straight-forward. Also, it doesn't look like any operator is defined to do this.

Where am I going wrong here? Would I be better off defining/converting to arrays?

Can any provide/point to a working example of mappings being passed to a funtion and combined?

Best Answer

the problem is not about storage or memory but about using a struct as a parameter. to avoid the first problem declare your function internal :

 function MappingCombiner(mapper  map1, mapper map2) internal{ 
     }

for the mapping assignation I don't know what do you try to do, your operation is erroneous. the operator + is for LValue (i.e. a variable or something that can be assigned to)