Skip to content

Commit

Permalink
Add function filter to type TokenMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Jan 14, 2021
1 parent aada854 commit 499ec3e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/core/src/Cardano/Wallet/Primitive/Types/TokenMap.hs
Expand Up @@ -49,6 +49,9 @@ module Cardano.Wallet.Primitive.Types.TokenMap
, toFlatList
, toNestedList

-- * Filtering
, filter

-- * Arithmetic
, add
, subtract
Expand Down Expand Up @@ -80,7 +83,7 @@ module Cardano.Wallet.Primitive.Types.TokenMap
) where

import Prelude hiding
( subtract )
( filter, subtract )

import Algebra.PartialOrd
( PartialOrd (..) )
Expand Down Expand Up @@ -124,6 +127,7 @@ import Quiet
import qualified Cardano.Wallet.Primitive.Types.TokenQuantity as TokenQuantity
import qualified Data.Aeson as Aeson
import qualified Data.Foldable as F
import qualified Data.List as L
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as Map
import qualified Data.Map.Strict.NonEmptyMap as NEMap
Expand Down Expand Up @@ -460,6 +464,13 @@ toNestedList
toNestedList =
fmap (fmap NEMap.toList) . Map.toList . unTokenMap

--------------------------------------------------------------------------------
-- Filtering
--------------------------------------------------------------------------------

filter :: (AssetId -> Bool) -> TokenMap -> TokenMap
filter f = fromFlatList . L.filter (f . fst) . toFlatList

--------------------------------------------------------------------------------
-- Arithmetic
--------------------------------------------------------------------------------
Expand Down

0 comments on commit 499ec3e

Please sign in to comment.