Другой пример, реализованный с помощью рекурсивных функций (возможно, не такой простой и быстрый, как другие, но сделанный с другим подходом):
let rec find (b: 'T list) (a: 'T) : bool * 'T list =
match b with
| [] -> false, b
| h :: t ->
if h = a then
true, t
else
let res, restB = a |> find t
res, h :: restB
let rec merge (a: 'T list) (b: 'T list) (order: bool) : ('T * bool * bool) list =
match a with
| [] ->
if not(order) then
[]
else
merge b a false
| h :: t ->
let resA, newB = h |> find b
(h, resA || order, resA || not(order)) :: merge t newB order
let Merge (a: 'T list) (b: 'T list) : ('T * bool * bool) list =
merge a b true
А для:
let dtl1 =
[DateTime.Today.AddDays(1.)
DateTime.Today.AddDays(2.)
DateTime.Today.AddDays(3.)
DateTime.Today.AddDays(4.)
DateTime.Today.AddDays(5.)
DateTime.Today.AddDays(6.)]
let dtl2 =
[DateTime.Today.AddDays(4.)
DateTime.Today.AddDays(5.)
DateTime.Today.AddDays(6.)
DateTime.Today.AddDays(7.)
DateTime.Today.AddDays(8.)
DateTime.Today.AddDays(9.)]
Merge dtl1 dtl2
Дает:
[(27.11.2011 0:00:00, true, false); (28.11.2011 0:00:00, true, false);
(29.11.2011 0:00:00, true, false); (30.11.2011 0:00:00, true, true);
(01.12.2011 0:00:00, true, true); (02.12.2011 0:00:00, true, true);
(03.12.2011 0:00:00, false, true); (04.12.2011 0:00:00, false, true);
(05.12.2011 0:00:00, false, true)]
Обновление : функция слияния была упрощена, чтобы упорядочить DateTimes в результате, аналогично другим ответам