 Apply a function to an amount's quantity (and its total price, if it has one).
transformAmount :: (Quantity -> Quantity) -> Amount -> Amount
transformAmount f a@Amount{aquantity=q,aprice=p} = a{aquantity=f q, aprice=f' <$> p}
  where
    f' (TotalPrice a@Amount{aquantity=pq}) = TotalPrice a{aquantity = f pq}
    f' p = p

-- | Divide an amount's quantity (and its total price, if it has one) by a constant.
div
transformAmount :: (Quantity -> Quantity) -> Amount -> Amount
transformAmount f a@Amount{aquantity=q,aprice=p} = a{aquantity=f q, aprice=f' <$> p}
  where
    f' (TotalPrice a@Amount{aquantity=pq}) = TotalPrice a{aquantity = f pq}
    f' p = p

-- | Divide an amount's quantity (and its total price, if it has one) by a constant.
transformAmount f a@Amount{aquantity=q,aprice=p} = a{aquantity=f q, aprice=f' <$> p}
  where
    f' (TotalPrice a@Amount{aquantity=pq}) = TotalPrice a{aquantity = f pq}
    f' p = p

-- | Divide an amount's quantity (and its total price, if it has one) by a constant.