I am creating two lists in liquidity and trying to process on them as follow:
type two_element = {
name: string;
value : nat;
}
type list1 = two_element list;
type list2 = two_element list;
Suppose I need to find out whether some "name" in list1 is present with smaller "value" in list2 or not, if the "value" in list 2 is smaller, get a two_element list of all those "name" with the value difference.
A simple example of what I want to get is as follow: input lists:
let list1 = [{"A"; 5}; {"B"; 10}; {"C"; 20};] in
let list2 = [{"A"; 15}; {"B"; 8}; {"C"; 15}; {"D";25};{"E"; 25}] in
output list:
list3 = [{"B"; 2}; {"C"; 5}]
I think I can iterate the list1
and compare each element's name by iterating it in list2
, but how to write the syntax of this iteration? Maybe using Loop? It's not very clear from the syntax and examples given in documentation to use the loop.
Also, I was thinking, maybe, I can map each element of both lists to another function using List.map
and it will return a two_element list containing the names and value difference but I am not sure how that can be done for the two lists simultaneously.
I couldn't find any example of List processing in this manner and spent some time in understanding the exact working of Loops and List.map but couldn't get any significant conclusion.