As well as the basic types, fi also allows the following complex types which usually work in conjunction with other types. Complex types can't be used in a literal way and have specific constructors for creating new variables.
Maps require a key and an element, and can form a large list of mapped elements. Keys must be unique for each entry, and can be used to retrieve a specific entry for a map.
A map key must be one of the following types:
We define the map type in the following way:
storage map[address => nat] balances;
This creates a map type variable, with a map key of type address, and a map item of type nat, stored as storage.balances.
An empty map can be defined using the following:
let map[int=>string] passages = new map(int, string);
The following operations can be used with maps
in(map, map_key) - returns bool if key exists as a map key in the map
length(map) - returns cardinal size of the map as a nat
get(map, map_key) - returns item with index key. Fails if key doesn't exist (it is advised to use in first)
push(map, map_key, map_item) - no return. Pushes item into map at index key. Will add the element if key doesn't exist, and update if it does (acts as an upsert)
drop(map, map_key) - no return. Removes the key/element pair from the map