-
-
Save AeroNotix/d609fcc8ad99f9e65f90 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
open Core.Std | |
let maybe_list this that = | |
match this with | |
| Some l -> | |
Some (List.append l [that]); | |
| None -> Some [that] | |
let group_by f l = | |
let ht = Hashtbl.Poly.create () in | |
List.fold | |
~f:(fun m el -> | |
let res = f el and | |
cur = Hashtbl.Poly.find ht el in | |
Hashtbl.Poly.replace ht cur (maybe_list cur el); | |
ht) | |
~init:ht l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment