I have a collection of key/value pairs contained inside an F# Map
type node = {myFloat:float, data1:int; data2:int;}
type nodesCollection = {metaData:int nodes:Map<float,node>}
let results = processData (nodes:Map<float,node>)
The function processData returns a list of tuples with the following signature
val results : (node * int * int * int * int) List
I would like to:
- Only work with the first item of the tuple (i.e. node)
- Iterate through either the key/value pairs in the Map or the list of nodes
- Replace the node values in the Map with those if the list in the key exist in both
- If the key doesn't exist in the Map added the node from the list to the Map
- Return the updated Map
Ignoring the fact that the returned tuple needs to be parsed, I would do something like this in C# if I was using a Dictionary<float,node>
foreach newNode in nodesInList
{
if (nodesCollection.nodes.Contains(newNode.myfloat))
nodesCollection.nodes[newNode.myfloat] = node
else
nodesCollection.nodes.Add(newNode.myfloat, node);
}
return nodesCollection.nodes
How would I approach this using a Map and functional style?