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 Dec 2, 2022
1 parent a64cd8a commit 0ffde6d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/primitive/lib/Cardano/Wallet/Primitive/Types/TokenMap.hs
Expand Up @@ -127,7 +127,7 @@ import Data.List.NonEmpty
import Data.Map.Strict
( Map )
import Data.Maybe
( mapMaybe )
( fromMaybe, mapMaybe )
import Data.Monoid.Monus
( Monus, OverlappingGCDMonoid, (<\>) )
import Data.Monoid.Null
Expand Down Expand Up @@ -805,7 +805,6 @@ 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
unsafeSubtract a b = fromMaybe bailOut (a </> b)
where
acc c (asset, quantity) =
adjustQuantity c asset (`TokenQuantity.unsafeSubtract` quantity)
bailOut = error "TokenMap.unsafeSubtract"

0 comments on commit 0ffde6d

Please sign in to comment.