Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I merge two lists of dates in F#?

Tags:

f#

There are two lists of dates (no assumptions can be made regarding list order)

//first list
[date_a; date_b; date_c]
//second list
[date_A; date_B; date_C]

I am looking for a function that returns the following as a list of entries: the date is unique key (a single date will appear only once in the list)

-> (date, true, true) in case both lists contained the date
-> (date, true, false) in case the first list contained the date
-> (date, false, true) in case the second list contained the date
(there will be no (date, false, false) entries)
like image 706
Henrik K Avatar asked Dec 22 '22 05:12

Henrik K


1 Answers

let showMembership l1 l2 = 
        let s1 = Set.ofList l1
        let s2 = Set.ofList l2
        Set.union s1 s2
            |> Set.map (fun d -> (d, Set.contains d s1, Set.contains d s2))

Note this returns a Set but you can use List.ofSeq to create a list if required

like image 166
Lee Avatar answered Jan 05 '23 05:01

Lee