dev: transactionInferCostsFromEquity: clarify partitionPs
This commit is contained in:
parent
6d849e06f5
commit
9c5bcfea85
@ -245,15 +245,17 @@ transactionInferCostsFromEquity dryrun acctTypes t = first (annotateErrorWithTra
|
|||||||
npostings = zip [0..] $ tpostings t
|
npostings = zip [0..] $ tpostings t
|
||||||
transformIndexedPostingsF f = evalStateT . fmap (appEndo . foldMap Endo) . traverse f
|
transformIndexedPostingsF f = evalStateT . fmap (appEndo . foldMap Endo) . traverse f
|
||||||
|
|
||||||
-- Sort postings into pairs of conversion postings, costful postings, and other postings
|
-- Sort posting numbers into three lists (stored in two pairs), like so:
|
||||||
|
-- (conversion postings, (costful postings, other postings)).
|
||||||
partitionPs = fmap fst . foldrM select (([], ([], [])), Nothing)
|
partitionPs = fmap fst . foldrM select (([], ([], [])), Nothing)
|
||||||
select np@(_, p) ((cs, others@(ps, os)), Nothing)
|
where
|
||||||
| isConversion p = Right ((cs, others), Just np)
|
select np@(_, p) ((cs, others@(ps, os)), Nothing)
|
||||||
| hasCost p = Right ((cs, (np:ps, os)), Nothing)
|
| isConversion p = Right ((cs, others), Just np)
|
||||||
| otherwise = Right ((cs, (ps, np:os)), Nothing)
|
| hasCost p = Right ((cs, (np:ps, os)), Nothing)
|
||||||
select np@(_, p) ((cs, others), Just lst)
|
| otherwise = Right ((cs, (ps, np:os)), Nothing)
|
||||||
| isConversion p = Right (((lst, np):cs, others), Nothing)
|
select np@(_, p) ((cs, others), Just lst)
|
||||||
| otherwise = Left "Conversion postings must occur in adjacent pairs"
|
| isConversion p = Right (((lst, np):cs, others), Nothing)
|
||||||
|
| otherwise = Left "Conversion postings must occur in adjacent pairs"
|
||||||
|
|
||||||
-- Given a pair of indexed conversion postings, and a state consisting of lists of
|
-- Given a pair of indexed conversion postings, and a state consisting of lists of
|
||||||
-- costful and costless non-conversion postings, create a function which adds a conversion cost
|
-- costful and costless non-conversion postings, create a function which adds a conversion cost
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user