Skip to content

Instantly share code, notes, and snippets.

@db0company
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save db0company/9415493 to your computer and use it in GitHub Desktop.
Save db0company/9415493 to your computer and use it in GitHub Desktop.
(* Take 2 lists, return a tuple with the elements that are in both and the *)
(* elements that are only in first list, and elements only in second list *)
let list_diff l1 l2 =
let (shared, only_in_first) = List.fold_left
(fun (s, o) e -> if List.mem e l2 then (e::s, o) else (s, e::no))
([], []) l1 in
let only_in_second = List.fold_left
(fun o e -> if List.mem e shared then o else e::o) [] l2 in
(shared, only_in_first, only_in_second)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment