aboutsummaryrefslogtreecommitdiff
path: root/server/src/Util/List.hs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/Util/List.hs')
-rw-r--r--server/src/Util/List.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/server/src/Util/List.hs b/server/src/Util/List.hs
new file mode 100644
index 0000000..4e22ba8
--- /dev/null
+++ b/server/src/Util/List.hs
@@ -0,0 +1,13 @@
+module Util.List
+ ( groupBy
+ ) where
+
+import Control.Arrow ((&&&))
+import Data.Function (on)
+import qualified Data.List as L
+
+groupBy :: forall a b. (Ord b) => (a -> b) -> [a] -> [(b, [a])]
+groupBy f =
+ map (f . head &&& id)
+ . L.groupBy ((==) `on` f)
+ . L.sortBy (compare `on` f)