Skip to content

Instantly share code, notes, and snippets.

@AeroNotix
Created April 26, 2014 15:56
Show Gist options
  • Save AeroNotix/11323642 to your computer and use it in GitHub Desktop.
Save AeroNotix/11323642 to your computer and use it in GitHub Desktop.
open Core.Std
let maybe_list this that =
match this with
| Some l ->
(List.append l [that]);
| None -> [that]
let group_by f l =
let ht = Hashtbl.Poly.create () in
List.fold
~f:(fun () el ->
let res = f el in
let cur = Hashtbl.Poly.find ht res in
Hashtbl.Poly.replace ht res (maybe_list cur el);
())
~init:() l;
ht
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment