如何在F#中合并两个日期列表?

Hen*_*k K 4 f#

有两个日期列表(没有关于列表顺序的假设)

//first list
[date_a; date_b; date_c]
//second list
[date_A; date_B; date_C]
Run Code Online (Sandbox Code Playgroud)

我正在寻找一个函数,它返回以下条目列表:日期是唯一键(单个日期只在列表中出现一次)

-> (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)
Run Code Online (Sandbox Code Playgroud)

Lee*_*Lee 7

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))
Run Code Online (Sandbox Code Playgroud)

请注意,这会返回一个Set,但您可以List.ofSeq根据需要使用它来创建列表