You might consider using an F# Set or a .NET System.Collections.Generic.HashSet<> of (key,val) tuples instead of a dictionary. Then the merge operation is simply the union of the two sets. This might be less efficient but I think it better captures the semantics of what you're trying to do.

By on 11/15/2010 11:19 AM ()

This will only work if you do some work on the types of "key" and "val" - I think I saw that the F#-set need some implemented interfaces (compareable?) and of course you will end up havíng the situation where ("favColor", "blue") from the first set and ("favColor","red") from the second will *both* end up in the result set - a behavior normally neither wanted nor supported for the Dictianry-kind of scenarios (you either end up having exceptions if you use *add* or just overwriting older values with my *solution*)

By on 11/15/2010 10:02 PM ()

Hi,

do you use the "Map"-Dictionary from F# or the System.Collection.Generic.Dictionary?

The first one is inmutable by design, the second one can be updated. In either case the simplest way is to take/copy the first Dictionary and then check/add the values of the second. If you use the System.Collecgtion. .... one you can just use something like

secondDict |> Seq.iter (fun kvp -> copy.[kvp.Key] <- kvp.Value)

to get the job done (assuming copy is the destination-Dict and secondDict the one you want to add)

By on 11/15/2010 7:09 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper