FMGVXDGYAU36I3WXAAM77IITTMQ3IF3J66FQKOD6IULF5VYXMB7AC
eqCardName, eqQuantity, eqCategory :: Card -> Card -> Bool
eqCardName (Card {name = x}) (Card {name = y}) = x == y
eqQuantity (Card {quantity = x}) (Card {quantity = y}) = x == y
eqCategory (Card {category = x}) (Card {category = y}) = x == y
partialEqCard :: Eq a => (Card -> a) -> Card -> Card -> Bool
partialEqCard f x y = f x == f y
go acc lx@(x:xs) ly@(y:ys)
| x < y = go (Remove x : acc) xs ly
| x > y = go (Add x : acc) lx ys
go acc lx@(x : xs) ly@(y : ys)
| name x < name y = go (Remove x : acc) xs ly
| name x > name y = go (Add x : acc) lx ys
| not $ partialEqCard quantity x y =
go
( ChangeQuantity
( (fromIntegral . unrefine . quantity $ y)
- (fromIntegral . unrefine . quantity $ x)
)
: acc
)
xs
ys