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
}
let AcntSet =
{ Type = { asList : List AcntID, asInclude : Bool }
, default = { asList = [] : List AcntID, asInclude = False }
}
let ShadowMatch =
{ Type =
{ smFrom : List AcntID
, smTo : List AcntID
{ smFrom : AcntSet.Type
, smTo : AcntSet.Type
, smDate : Optional MatchDate
, smVal : MatchVal.Type
}
, default =
{ smFrom = [] : List AcntID
, smTo = [] : List AcntID
{ smFrom = AcntSet.default
, smTo = AcntSet.default
, smDate = None MatchDate
, smVal = MatchVal.default
}
@ -309,4 +314,5 @@ in { CurID
, TransferTarget
, ShadowMatch
, ShadowTransfer
, AcntSet
}

View File

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

View File

@ -171,8 +171,8 @@ shadowMatches ShadowMatch {smFrom, smTo, smDate, smVal} tx = do
&& valRes
where
tx_ = bttTx tx
memberMaybe _ [] = True
memberMaybe xs ys = xs `elem` ys
memberMaybe x AcntSet {asList, asInclude} =
(if asInclude then id else not) $ x `elem` asList
balanceTransfers :: [BudgetTxType] -> [BudgetTx]
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 "Budget" "Budget" "(./dhall/Types.dhall).Budget"
, SingleConstructor "Transfer" "Transfer" "(./dhall/Types.dhall).Transfer"
, SingleConstructor "AcntSet" "AcntSet" "(./dhall/Types.dhall).AcntSet.Type"
, SingleConstructor "ShadowMatch" "ShadowMatch" "(./dhall/Types.dhall).ShadowMatch.Type"
, SingleConstructor "ShadowTransfer" "ShadowTransfer" "(./dhall/Types.dhall).ShadowTransfer"
]
@ -316,6 +317,10 @@ deriving instance Eq ShadowTransfer
deriving instance Hashable ShadowTransfer
deriving instance Eq AcntSet
deriving instance Hashable AcntSet
deriving instance Eq ShadowMatch
deriving instance Hashable ShadowMatch