Skip to content

Commit

Permalink
Use filter instead of mapMaybe.
Browse files Browse the repository at this point in the history
We can now eliminate the auxilliary `noDust` function.
  • Loading branch information
jonathanknowles committed May 12, 2020
1 parent d7b7c09 commit 5f32c58
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/library/Cardano/CoinSelection/Algorithm/Migration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import Control.Monad.Trans.State
import Data.List.NonEmpty
( NonEmpty ((:|)) )
import Data.Maybe
( fromMaybe, mapMaybe )
( fromMaybe )
import Data.Word
( Word16 )
import GHC.Generics
Expand Down Expand Up @@ -119,13 +119,13 @@ selectCoins options (BatchSize batchSize) utxo =
inputs = coinMapFromList inputEntries
outputs = mempty
change =
let chgs = mapMaybe (noDust . entryValue) inputEntries
in if null chgs then [C.succ threshold] else chgs
if null nonDustInputCoins
then [C.succ threshold]
else nonDustInputCoins
threshold = unDustThreshold dustThreshold
noDust :: Coin -> Maybe Coin
noDust c
| isDust dustThreshold c = Nothing
| otherwise = Just c
nonDustInputCoins = filter
(not . isDust dustThreshold)
(entryValue <$> inputEntries)

-- | Attempt to balance the coin selection by reducing or increasing the
-- change values based on the computed fees.
Expand Down

0 comments on commit 5f32c58

Please sign in to comment.