Skip to content

Instantly share code, notes, and snippets.

@fmap
Created August 20, 2014 16:48
Show Gist options
  • Save fmap/59c08056e233925d0275 to your computer and use it in GitHub Desktop.
Save fmap/59c08056e233925d0275 to your computer and use it in GitHub Desktop.
import Prelude hiding (span, head, null)
import Control.Monad (liftM2)
import Data.Vector (Vector, null, empty, cons, span, head, thaw, freeze)
import qualified Data.Vector.Algorithms.Intro as Intro (sort)
group :: Eq a => Vector a -> Vector (Vector a)
group vs | null vs = empty
| otherwise = a `cons` group b where (a, b) = span (== head vs) vs
sort :: Ord a => Vector a -> IO (Vector a)
sort vs = thaw vs >>= liftM2 (>>) Intro.sort freeze
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment