https://gist.github.com/carlohamalainen/5087207.js

S. Doaitse Swierstra pointed out that the Data.List.Grouping package may be more appropriate here.