aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Utils/List.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/Utils/List.elm')
-rw-r--r--src/client/elm/Utils/List.elm13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/client/elm/Utils/List.elm b/src/client/elm/Utils/List.elm
new file mode 100644
index 0000000..85cdc24
--- /dev/null
+++ b/src/client/elm/Utils/List.elm
@@ -0,0 +1,13 @@
+module Utils.List
+ ( groupBy
+ ) where
+
+import Dict
+
+groupBy : (a -> comparable) -> List a -> List (comparable, List a)
+groupBy f xs =
+ let addItem item dict =
+ let groupItems = Dict.get (f item) dict |> Maybe.withDefault []
+ in Dict.insert (f item) (item :: groupItems) dict
+ in List.foldr addItem Dict.empty xs
+ |> Dict.toList