XBFPOITOZLMUZROJCW2YAUHFTVKPZMRO5GQL36BACBS2ELIU4R4QC
U3PXWO2PKW4XI4NXYMEQT44SXBQDVFZBDBW6YYOFSMANGI53V4ZQC
O7ZBGSRLERE2KAOQHQTO5B3MOMW5Z2JRR33GG3TBCTXIMXBRF3UQC
XAMFHYIWLYWVS52I3PNB7QB2YUBJQI3ORGFRTJOKW55GOFTYWRYQC
SNYOEZI7JMTLJNLM2YTAHBPJEKK2BJZJDOHRIX5676JCF2VNET3QC
R6GLORFO6COA5R7GFFHEZW7FXFJIJB6PTCSF3GBUZSETCE6IW23QC
P2KQ6PRM6HH2NQFXCTQIMGTAKXIG6BQ32IBYTKBSP4NWTZ4JLGGAC
C3BUGSBWBKOXFFB6TIHDLQVFV65OKKW6KEUVMP4O2XP3RYMPJ5QAC
FUOJJ2E7WNHF2NNKBI7MF254TU5Z5VOEKMO2XAJMY7RDOUQTMG6QC
EGR6GRLMIJLVMRVVGEC55F4JXBTOUMNN7NHKAYUWERFDLZF35Q5QC
SD6I6WVNJ4O5SIMHLJXQXU3NHKZF7HIL4REB7JQENW4N625KCZZQC
EMCOZGNBKFXT5LPGK7I57W2AOAUPAZSUYFRQUZJ6ZFGY5WWTQVLQC
6VA5CXBLQPHAZ2SL37OZVOI6D52HFXQUGLONJWAA7JSA7SCORBMAC
OQQ45NRBSXM5JXRTLDLP7CEBR4LPBAFY46AQHZTO2TXJMRKQVJNAC
SCI4JXPAPVL5I2GGL2BLXXSQKAD4Z5O2RTS4UODNFVKNC262ABIAC
D74P5SQWEN64WODTOQ4U6X4TATZRLAARILGIP6HDD4S2KUXMTGHQC
FMGVXDGYAU36I3WXAAM77IITTMQ3IF3J66FQKOD6IULF5VYXMB7AC
argName (Arg x _) = x
argCard (Arg _ x) = x
in argCard <$> (Data.Foldable.find ((== cname') . argName) . runDeckList $ xs)
-- | Type to track changes in a `DeckList`
data DeckDifference
= Add !Card
| Remove !CardName
| ChangeCard
!CardName
!(PositiveNumber -> Maybe PositiveNumber)
!(Category -> Category)
type DeckDiff = [DeckDifference]
in (Map.lookup cname' . runDeckList $ xs)
diff :: DeckList -> DeckList -> DeckDiff
diff left right =
let deckSort = map (\(Arg _ x) -> x) . Set.toDescList . runDeckList
in go mempty (deckSort left) (deckSort right)
where
go :: DeckDiff -> [Card] -> [Card] -> DeckDiff
go acc [] [] = acc
go acc xs [] = acc ++ (Remove <$> map name xs)
go acc [] ys = acc ++ (Add <$> ys)
go acc lx@(x : xs) ly@(y : ys)
| name x < name y = go (Remove (name x) : acc) xs ly
| name x > name y = go (Add x : acc) lx ys
| otherwise =
case (partialEqCard quantity x y, partialEqCard category x y) of
(True, True) -> go acc xs ys
(False, False) -> go (ChangeCard (name x) (calcQuantity x y) (const $ category y) : acc) xs ys
(False, _) -> go (ChangeCard (name x) (calcQuantity x y) id : acc) xs ys
(_, False) -> go (ChangeCard (name x) Just (const $ category y) : acc) xs ys
runQuantity = fromIntegral @_ @Int . unrefine . runNumber . quantity
delta x y = runQuantity y - runQuantity x
newQuantity a
| a < 1 = Nothing
| otherwise = PositiveNumber <$> (refineFail . fromIntegral $ a)
calcQuantity x y = newQuantity . (+ delta x y) . fromIntegral . unrefine . runNumber