From 5c110716cfda6e616a795edd12f2012b132dca9f Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 2 Apr 2017 17:51:12 +0200 Subject: Add a chart on payments by month by categories --- src/client/Utils/List.elm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/client/Utils/List.elm') diff --git a/src/client/Utils/List.elm b/src/client/Utils/List.elm index cc57d9f..8e26e85 100644 --- a/src/client/Utils/List.elm +++ b/src/client/Utils/List.elm @@ -1,9 +1,11 @@ module Utils.List exposing ( groupBy , mean + , links ) import Dict +import Maybe.Extra as Maybe groupBy : (a -> comparable) -> List a -> List (comparable, List a) groupBy f xs = @@ -15,3 +17,20 @@ groupBy f xs = mean : List Int -> Int mean xs = (List.sum xs) // (List.length xs) + +links : List a -> List (a, a) +links xs = + let reversed = List.reverse xs + in List.foldr + (\x acc -> + case Maybe.map Tuple.first (List.head acc) of + Just y -> + (x, y) :: acc + _ -> + acc + ) + (case reversed of + x :: y :: _ -> [(y, x)] + _ -> [] + ) + (List.reverse << List.drop 2 <| reversed) -- cgit v1.2.3