From 5f32c58135960ac6d3189364ecf023430dfb533f Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Tue, 12 May 2020 05:12:34 +0000 Subject: [PATCH] Use `filter` instead of `mapMaybe`. We can now eliminate the auxilliary `noDust` function. --- .../Cardano/CoinSelection/Algorithm/Migration.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/library/Cardano/CoinSelection/Algorithm/Migration.hs b/src/library/Cardano/CoinSelection/Algorithm/Migration.hs index 0f2854141..ff4187695 100644 --- a/src/library/Cardano/CoinSelection/Algorithm/Migration.hs +++ b/src/library/Cardano/CoinSelection/Algorithm/Migration.hs @@ -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 @@ -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.