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 +++++++++++++++++++ src/client/Utils/Maybe.elm | 34 ---------------------------------- 2 files changed, 19 insertions(+), 34 deletions(-) delete mode 100644 src/client/Utils/Maybe.elm (limited to 'src/client/Utils') 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) diff --git a/src/client/Utils/Maybe.elm b/src/client/Utils/Maybe.elm deleted file mode 100644 index 46456e1..0000000 --- a/src/client/Utils/Maybe.elm +++ /dev/null @@ -1,34 +0,0 @@ -module Utils.Maybe exposing - ( isJust - , cat - , toList - , orElse - ) - -isJust : Maybe a -> Bool -isJust maybe = - case maybe of - Just _ -> True - Nothing -> False - -cat : List (Maybe a) -> List a -cat = - List.foldr - (\mb xs -> - case mb of - Just x -> x :: xs - Nothing -> xs - ) - [] - -toList : Maybe a -> List a -toList mb = - case mb of - Just a -> [a] - Nothing -> [] - -orElse : Maybe a -> Maybe a -> Maybe a -orElse mb1 mb2 = - case mb1 of - Just x -> Just x - Nothing -> mb2 -- cgit v1.2.3