Created
April 26, 2014 15:28
-
-
Save xandkar/11322931 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
open Core_kernel.Std | |
let group_by l f = | |
List.fold_left l ~init:[] ~f:(fun groups x -> | |
let y = f x in | |
let group = | |
match List.Assoc.find groups y with | |
| Some xs -> x :: xs | |
| None -> [x] | |
in | |
List.Assoc.add groups y group | |
) |
Author
xandkar
commented
Apr 26, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment