const c:bool=isNone(a); // returns true if a is Noneconst d:bool=isSome(a); // returns true if a is Some(_)const e: nat =getSome(b):// extract the value (if any) or fail
List
List type represents list of same-type elements; a list can be declared as follow:
let l:nat list = (List.empty(): nat list); // empty listlet l1:nat list = [12n, 13n]; // literal list
let ls: nat =l.size();
let lh: nat =l.head();
let lt:nat list =l.tail();
let l2:nat list =l.prepend(14n);
let l3:nat list =l.mapWith((a: nat) => (a * 2n));
let l4:nat list =l.filter((a: nat) => (a <= 13n));
prepend, mapWith and filter are applied in-place if used over storage fields. Their types are unit instead of nat list. To apply as expression, surround the storage field with copy().
Set
Sets are list of different elements of the same-type.
let s:nat set = (Set.empty(): nat set); // empty setlet s1:nat set = ([12n, 13n]: nat set); // literal set
let ss: nat =s.size();
let b:bool=s.mem(13n);
let s2:nat set =s1.update(18n,true); // addlet s2:nat set =s2.update(18n,false); // remove
update are applied in-place if used over storage fields. Their types are unit instead of nat set. To apply as expression, surround the storage field with copy().
Tuple
A tuple is a pair, triple, etc of different types; you can define a tuple as follow:
let atuple: (int, string) = (12,"hello");
Record
Map & Big_map
('a, 'b) Map and ('a, 'b) Big_map are collections of 'b indexed by a key 'a; 'a should be a comparable.
update, remove, mapWith, fold, filter are applied in-place if used over storage fields. Their types are unit instead of nat set. To apply as expression, surround the storage field with copy().
Map
let m: (string,nat) map = (Map.empty(): (string, nat) map);
While calling some of the composed type specific functions, if the left-hand is storage field, the modification will be automatically assigned to the field storage.
this.flist.prepend (12n); // this has type unit, an modify flist prepending 12n
To avoid this behaviour, you can use the copy helper function.