4K7I3AJQDM4TLBF45D5FTFH2STCRYVQJQSPDI3UW4TEIW33AAYNQC
R $
let newCard = mkCard cardname initialCategory initialCopies
in Map.alter
( \case
Nothing -> Just newCard
Just x ->
Just $
over
(categories . ix (toText initialCategory) . copies)
(uncheckedAdd initialCopies)
x
)
(toText cardname)
$ unR decklist
R $ Map.alter updateCard (toText cardname) $ unR decklist
where
updateCard = \case
Nothing -> Just $ mkCard cardname initialCategory initialCopies
Just x ->
case x ^? categories . ix (toText initialCategory) of
Nothing ->
pure $
x
& categories . at (toText initialCategory)
?~ Category initialCategory initialCopies
Just y ->
let mergedCategory = (y & copies %~ uncheckedAdd initialCopies)
in pure $ x & categories . at (toText initialCategory) ?~ mergedCategory