Skip to content

Instantly share code, notes, and snippets.

@andyfriesen
Last active August 29, 2015 14:05
Show Gist options
  • Save andyfriesen/825be8da046e3ed7f213 to your computer and use it in GitHub Desktop.
Save andyfriesen/825be8da046e3ed7f213 to your computer and use it in GitHub Desktop.
-- sort function, optimized for lists
-- TODO - profiling
sortBy compare = head . head . dropWhile (isn't unsafeCoerce . drop 1) . group . iterate bubble
where
bubble [] = []
bubble [x] = [x]
bubble (x:y:ys) =
if compare x y == GT
then y:(bubble (x:ys))
else
if compare x y == EQ
then x:(bubble (y:ys))
else
if compare x y == LT
then x:(bubble (y:ys))
else x:y:(bubble ys)
isn't f x = if f x then False else True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment