diff options
author | Joris | 2017-04-02 17:51:12 +0200 |
---|---|---|
committer | Joris | 2017-04-02 21:07:08 +0200 |
commit | 5c110716cfda6e616a795edd12f2012b132dca9f (patch) | |
tree | 71c3d04780302edf0648bec1cd914757cdbb2883 /src/client/Utils | |
parent | 64ff4707fdcd81c27c6be9903c3c82bc543ef016 (diff) |
Add a chart on payments by month by categories
Diffstat (limited to 'src/client/Utils')
-rw-r--r-- | src/client/Utils/List.elm | 19 | ||||
-rw-r--r-- | src/client/Utils/Maybe.elm | 34 |
2 files changed, 19 insertions, 34 deletions
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 |