From ac8a7c6210e2f430a3015e8004ff0726ef24d63b Mon Sep 17 00:00:00 2001 From: Joris Date: Wed, 6 Apr 2016 14:28:16 +0200 Subject: Add payments by month in stat --- src/client/elm/Utils/List.elm | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/client/elm/Utils/List.elm (limited to 'src/client/elm/Utils') 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 -- cgit v1.2.3