Skip to content

Instantly share code, notes, and snippets.

@carymrobbins
Created December 19, 2014 05:37
Show Gist options
  • Save carymrobbins/c9940097d5702f6b2a9f to your computer and use it in GitHub Desktop.
Save carymrobbins/c9940097d5702f6b2a9f to your computer and use it in GitHub Desktop.
An implementation of groupBy which returns a list of mono traversable
import ClassyPrelude
groupBy' :: IsSequence seq => (Element seq -> Element seq -> Bool) -> seq -> [MinLen (Succ Zero) seq]
groupBy' eq s = case uncons s of
Nothing -> mempty
Just (x, xs) -> mlcons x (toMinLenZero ys) : groupBy' eq zs
where
(ys,zs) = span (eq x) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment