Skip to content

Commit

Permalink
Simplify implementation of TokenMap.unsafeSubtract.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Jun 2, 2023
1 parent 87e05bf commit 570f8aa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/primitive/lib/Cardano/Wallet/Primitive/Types/TokenMap.hs
Expand Up @@ -160,6 +160,8 @@ import Numeric.Natural
( Natural )
import Quiet
( Quiet (..) )
import Safe
( fromJustNote )

import qualified Cardano.Wallet.Primitive.Types.TokenQuantity as TokenQuantity
import qualified Data.Aeson as Aeson
Expand Down Expand Up @@ -783,7 +785,5 @@ mapAssetIds f m = fromFlatList $ first f <$> toFlatList m
-- Throws a run-time exception if the pre-condition is violated.
--
unsafeSubtract :: TokenMap -> TokenMap -> TokenMap
unsafeSubtract a b = F.foldl' acc a $ toFlatList b
where
acc c (asset, quantity) =
adjustQuantity c asset (`TokenQuantity.unsafeSubtract` quantity)
unsafeSubtract b1 b2 = fromJustNote "TokenMap.unsafeSubtract" $
b1 `subtract` b2

0 comments on commit 570f8aa

Please sign in to comment.