Writing arrays and maps of arrays into blockchain

Hello! I have the next question:
Is it somehow possible to write arrays or even maps of arrays using Sophia Smart contracts?

Since Sophia is a functional language it does not have exactly the same native data structures as many imperative languages (like Solidity, Java, etc.). In Sophia you have maps, and lists, and you pick one representation depending on how you need to access your data. If you just need a collection of things and always use all of them you put them in a list, if you need to access individual elements you are probably better off storing them in a map.

But it is often easier with a concrete example, what data do you want to put in (maps of) arrays?


There is such a thing like a “byte array” but it is not probably the thing that you want. Instead, there are single linked lists and maps as @hanssv.chain said.
Assuming list is a good enough replacement for an array, you can of course use maps of them. Maybe a simple example will help

entrypoint list_test(l : list(int)) : list(int) =
  l ++ 1::[2,3,4,5] ++ [] // appends [1,2,3,4] to the end of l

entrypoint map_list_test(m : map(bool, list(bool))) : list(bool) = 
  m[true] ++ m[false] 
1 Like