diff options
author | Joris | 2015-10-04 21:06:23 +0200 |
---|---|---|
committer | Joris | 2015-10-04 21:06:23 +0200 |
commit | d920dd95be096dcaa2fa2314d729fdff52631fd6 (patch) | |
tree | 1e51b73c5bf77d7f9fb885141920a853b7a830f7 | |
parent | 7d03ea5a064b616b4aa5b6cf6db24019e59131ea (diff) |
Factor incomeDefinedForAll utilization
-rw-r--r-- | src/client/Model/Income.elm | 4 | ||||
-rw-r--r-- | src/client/Model/Payer.elm | 11 |
2 files changed, 9 insertions, 6 deletions
diff --git a/src/client/Model/Income.elm b/src/client/Model/Income.elm index ce30772..97a5652 100644 --- a/src/client/Model/Income.elm +++ b/src/client/Model/Income.elm @@ -25,9 +25,9 @@ incomeDecoder = ("creation" := timeDecoder) ("amount" := Json.int) -incomeDefinedForAll : List (UserId, List Income) -> Maybe Time +incomeDefinedForAll : List (List Income) -> Maybe Time incomeDefinedForAll usersIncomes = - let firstIncomes = map (head << sortBy .creation << snd) usersIncomes + let firstIncomes = map (head << sortBy .creation) usersIncomes in if all isJust firstIncomes then head << reverse << List.sort << map .creation << catMaybes <| firstIncomes else Nothing diff --git a/src/client/Model/Payer.elm b/src/client/Model/Payer.elm index af475bb..9fd1bb5 100644 --- a/src/client/Model/Payer.elm +++ b/src/client/Model/Payer.elm @@ -46,7 +46,7 @@ updatePayers payers userId creation amountDiff = case mbPayer of Just payer -> let postIncome = - incomeDefinedForAll (Dict.toList << mapValues .incomes <| payers) + payersIncomeDefinedForAll payers |> Maybe.map (\date -> creation > date) |> Maybe.withDefault False in if postIncome @@ -65,13 +65,12 @@ type alias ExceedingPayer = getOrderedExceedingPayers : Time -> Payers -> List ExceedingPayer getOrderedExceedingPayers currentTime payers = - let mbIncomeDefinedForAll = incomeDefinedForAll (Dict.toList << mapValues .incomes <| payers) - exceedingPayersOnPreIncome = + let exceedingPayersOnPreIncome = payers |> mapValues .preIncomePaymentSum |> Dict.toList |> exceedingPayersFromAmounts - in case mbIncomeDefinedForAll of + in case payersIncomeDefinedForAll payers of Just since -> let postPaymentPayers = payers @@ -92,6 +91,10 @@ getOrderedExceedingPayers currentTime payers = Nothing -> exceedingPayersOnPreIncome +payersIncomeDefinedForAll : Payers -> Maybe Time +payersIncomeDefinedForAll payers = + incomeDefinedForAll (List.map (.incomes << snd) << Dict.toList <| payers) + exceedingPayersFromAmounts : List (UserId, Int) -> List ExceedingPayer exceedingPayersFromAmounts userAmounts = let mbMinAmount = List.minimum << List.map snd <| userAmounts |