Complex Types
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
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:
string
bool
int
nat
bytes
mutez
timestamp
address
key_hash/pkh
We define the map type in the following way:
This creates a map type variable, with a map key of type address, and a map item of type nat, stored as storage.balances.
Empty Map
An empty map can be defined using the following:
Operations
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
These functions can be used as standalone functions, or as a variable modifier.
Big Map
Big maps work the same as normal maps, but have a few restrictions:
Big maps can only be declared as a storage variable
Only one big_map can exist for any given contract
The length() function doesn't work with big_maps
Big maps can't be constructed
We define the map type in the following way:
All functions, other then length, are applicable for big maps.
Lists
Lists are non-indexed arrays of a specified type, and are defined as follows:
This creates a list of the specified type - in this instance a list of strings, which can be accessed via storage.names.
Empty list
An empty map can be defined using the following:
Operations
The following operations are available for lists:
length(list) - returns cardinal size of a list as a nat
push(list, item) - pushes an item to a list
pop(list) - removes the last item from a list and returns it
These functions can be used as standalone functions, or as a variable modifier.
Set
Sets are similar to lists as we store a single type of data per entry, and can be declared as follows:
The set item type must be one of the following types (same as the map key):
string
bool
int
nat
bytes
mutez
timestamp
address
key_hash/pkh
Operations
The following operations are available for lists:
length(set) - returns cardinal size of a set as a nat
push(set, item) - pushes an item to a set
in(set, item) - returns bool if item exists in the set
drop(set, item) - no return. Removes the item from a set
These functions can be used as standalone functions, or as a variable modifier.
Contract
The contract type is the typed version of an address. Michelson contract types must also specify the type of the input parameter.
Option
Optional values can be set and then used within expressions. These values either hold "some" value, or "none". Optional values are defined by adding a question mark before another type:
We can convert any existing value to an optional value using the to_optional cast, or we can use the none function to create an optional variable with no value.
Last updated