Skip to content

Commit

Permalink
Add Monoid instance for TokenBundle.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Jan 11, 2021
1 parent 7bab9c2 commit 1484b3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/core/src/Cardano/Wallet/Primitive/Types/TokenBundle.hs
Expand Up @@ -126,6 +126,9 @@ instance NFData TokenBundle
instance Semigroup TokenBundle where
(<>) = add

instance Monoid TokenBundle where
mempty = empty

--------------------------------------------------------------------------------
-- Text serialization
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -155,6 +158,11 @@ buildMap = blockMapF . fmap (first $ id @String)
-- Construction
--------------------------------------------------------------------------------

-- | The empty token bundle.
--
empty :: TokenBundle
empty = TokenBundle (Coin 0) mempty

-- | Creates a token bundle from a coin and a flat list of token quantities.
--
-- If a token name appears more than once in the list under the same policy,
Expand Down
Expand Up @@ -19,7 +19,7 @@ import Test.Hspec.Core.QuickCheck
import Test.QuickCheck
( Arbitrary (..) )
import Test.QuickCheck.Classes
( eqLaws, semigroupLaws )
( eqLaws, monoidLaws, semigroupLaws, semigroupMonoidLaws )
import Test.Utils.Laws
( testLawsMany )
import Test.Utils.Laws.PartialOrd
Expand All @@ -33,8 +33,10 @@ spec =
describe "Class instances obey laws" $ do
testLawsMany @TokenBundle
[ eqLaws
, monoidLaws
, partialOrdLaws
, semigroupLaws
, semigroupMonoidLaws
]

--------------------------------------------------------------------------------
Expand Down

0 comments on commit 1484b3a

Please sign in to comment.