Last active
August 29, 2015 13:57
-
-
Save db0company/9415493 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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