Skip to content

Commit

Permalink
Add function subtract to TokenBundle.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Jan 12, 2021
1 parent 4277595 commit 323ccc1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/core/src/Cardano/Wallet/Primitive/Types/TokenBundle.hs
Expand Up @@ -37,6 +37,7 @@ module Cardano.Wallet.Primitive.Types.TokenBundle

-- * Arithmetic
, add
, subtract

-- * Quantities
, getQuantity
Expand All @@ -58,7 +59,7 @@ module Cardano.Wallet.Primitive.Types.TokenBundle
) where

import Prelude hiding
( negate, null )
( negate, null, subtract )

import Algebra.PartialOrd
( PartialOrd (..) )
Expand Down Expand Up @@ -248,6 +249,12 @@ add :: TokenBundle -> TokenBundle -> TokenBundle
add (TokenBundle (Coin c1) m1) (TokenBundle (Coin c2) m2) =
TokenBundle (Coin $ c1 + c2) (TokenMap.add m1 m2)

-- | Subtracts one token bundle from another.
--
subtract :: TokenBundle -> TokenBundle -> TokenBundle
subtract (TokenBundle (Coin c1) m1) (TokenBundle (Coin c2) m2) =
TokenBundle (Coin $ c1 - c2) (TokenMap.subtract m1 m2)

--------------------------------------------------------------------------------
-- Quantities
--------------------------------------------------------------------------------
Expand Down

0 comments on commit 323ccc1

Please sign in to comment.