Why not. If the lists are very long and they have large overlaps it may not be very efficient though.

You can also use set union:

1
2
3
4
5
6
let l1 = [1;2;3]
let l2 = [2;3;4]

let l3 = List.concat [l1; l2] |> Seq.distinct

let l3 = Set.ofList l1 |> Set.union (Set.ofList l2)
By on 6/21/2010 9:13 AM ()

Hi,

some quick thoughts on this:

Don't use Set for this but System.Collections.Generic.Hashset for two simple reasons - first Hashset works with any datatype (supporting some meaningful Compare/GetHashValue) and second for HashSet.SetUnion there is a overload that takes a IEnumerable (a.k.a. Seq) as input - so you don't have to first create a Set out of your second List.

By on 6/21/2010 9:18 PM ()
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