ENH allow specifying inclusion/exclusion for shadow matches

This commit is contained in:
Nathan Dwarshuis 2023-02-26 11:27:11 -05:00
parent ae3109a4ba
commit ad2937880c
4 changed files with 18 additions and 7 deletions

View File

@ -230,16 +230,21 @@ let Transfer =
, transCurrency : CurID , transCurrency : CurID
} }
let AcntSet =
{ Type = { asList : List AcntID, asInclude : Bool }
, default = { asList = [] : List AcntID, asInclude = False }
}
let ShadowMatch = let ShadowMatch =
{ Type = { Type =
{ smFrom : List AcntID { smFrom : AcntSet.Type
, smTo : List AcntID , smTo : AcntSet.Type
, smDate : Optional MatchDate , smDate : Optional MatchDate
, smVal : MatchVal.Type , smVal : MatchVal.Type
} }
, default = , default =
{ smFrom = [] : List AcntID { smFrom = AcntSet.default
, smTo = [] : List AcntID , smTo = AcntSet.default
, smDate = None MatchDate , smDate = None MatchDate
, smVal = MatchVal.default , smVal = MatchVal.default
} }
@ -309,4 +314,5 @@ in { CurID
, TransferTarget , TransferTarget
, ShadowMatch , ShadowMatch
, ShadowTransfer , ShadowTransfer
, AcntSet
} }

View File

@ -4,7 +4,7 @@ let List/map =
let T = let T =
./Types.dhall ./Types.dhall
sha256:3c6121710cb1d4ed84d9cb7ab6589fdcea79d1e4e07b33b22bd84e52506ea80f sha256:1c88b66bd88326bf72f1eb2d6a3b4d6d57fd51a473482390b2d0b0486a9a60e7
let nullSplit = let nullSplit =
\(a : T.SplitAcnt) -> \(a : T.SplitAcnt) ->

View File

@ -171,8 +171,8 @@ shadowMatches ShadowMatch {smFrom, smTo, smDate, smVal} tx = do
&& valRes && valRes
where where
tx_ = bttTx tx tx_ = bttTx tx
memberMaybe _ [] = True memberMaybe x AcntSet {asList, asInclude} =
memberMaybe xs ys = xs `elem` ys (if asInclude then id else not) $ x `elem` asList
balanceTransfers :: [BudgetTxType] -> [BudgetTx] balanceTransfers :: [BudgetTxType] -> [BudgetTx]
balanceTransfers ts = snd $ L.mapAccumR go initBals $ L.sortOn (btWhen . bttTx) ts balanceTransfers ts = snd $ L.mapAccumR go initBals $ L.sortOn (btWhen . bttTx) ts

View File

@ -54,6 +54,7 @@ makeHaskellTypesWith
, SingleConstructor "Income" "Income" "(./dhall/Types.dhall).Income" , SingleConstructor "Income" "Income" "(./dhall/Types.dhall).Income"
, SingleConstructor "Budget" "Budget" "(./dhall/Types.dhall).Budget" , SingleConstructor "Budget" "Budget" "(./dhall/Types.dhall).Budget"
, SingleConstructor "Transfer" "Transfer" "(./dhall/Types.dhall).Transfer" , SingleConstructor "Transfer" "Transfer" "(./dhall/Types.dhall).Transfer"
, SingleConstructor "AcntSet" "AcntSet" "(./dhall/Types.dhall).AcntSet.Type"
, SingleConstructor "ShadowMatch" "ShadowMatch" "(./dhall/Types.dhall).ShadowMatch.Type" , SingleConstructor "ShadowMatch" "ShadowMatch" "(./dhall/Types.dhall).ShadowMatch.Type"
, SingleConstructor "ShadowTransfer" "ShadowTransfer" "(./dhall/Types.dhall).ShadowTransfer" , SingleConstructor "ShadowTransfer" "ShadowTransfer" "(./dhall/Types.dhall).ShadowTransfer"
] ]
@ -316,6 +317,10 @@ deriving instance Eq ShadowTransfer
deriving instance Hashable ShadowTransfer deriving instance Hashable ShadowTransfer
deriving instance Eq AcntSet
deriving instance Hashable AcntSet
deriving instance Eq ShadowMatch deriving instance Eq ShadowMatch
deriving instance Hashable ShadowMatch deriving instance Hashable ShadowMatch