@@ -120,7 +120,6 @@ import Prelude
120120import Control.Alt ((<|>))
121121import Control.Alternative (class Alternative )
122122import Control.Lazy (class Lazy , defer )
123- import Control.Monad.Eff (foreachE )
124123import Control.Monad.Rec.Class (class MonadRec , Step (..), tailRecM2 )
125124import Control.Monad.ST as ST
126125import Data.Array.ST as STA
@@ -131,7 +130,7 @@ import Data.Foldable (foldl, foldr, foldMap, fold, intercalate, elem, notElem, f
131130import Data.Maybe (Maybe (..), maybe , isJust , fromJust )
132131import Data.Traversable (scanl , scanr ) as Exports
133132import Data.Traversable (sequence , traverse )
134- import Data.Tuple (Tuple (..), fst , snd , uncurry )
133+ import Data.Tuple (Tuple (..), fst , snd )
135134import Data.Unfoldable (class Unfoldable , unfoldr )
136135import Partial.Unsafe (unsafePartial )
137136import Unsafe.Coerce (unsafeCoerce )
@@ -903,16 +902,16 @@ nubEq = nubByEq eq
903902nubBy :: forall a . (a -> a -> Ordering ) -> Array a -> Array a
904903nubBy comp xs = case head indexedAndSorted of
905904 Nothing -> []
906- Just x -> map snd $ sortWith fst $ pureST do
905+ Just x -> map snd $ sortWith fst $ ST .run do
907906 -- TODO: use NonEmptyArrays here to avoid partial functions
908- result <- unsafeThaw $ singleton x
909- foreachE indexedAndSorted \pair@(Tuple i x') -> do
910- lst <- snd <<< unsafePartial (fromJust <<< last) <$> unsafeFreeze result
911- when (comp lst x' /= EQ ) $ void $ pushSTArray result pair
912- unsafeFreeze result
907+ result <- STA . unsafeThaw $ singleton x
908+ ST .foreach indexedAndSorted \pair@(Tuple i x') -> do
909+ lst <- snd <<< unsafePartial (fromJust <<< last) <$> STA . unsafeFreeze result
910+ when (comp lst x' /= EQ ) $ void $ STA .push pair result
911+ STA . unsafeFreeze result
913912 where
914913 indexedAndSorted :: Array (Tuple Int a )
915- indexedAndSorted = sortBy (\x y -> comp (snd x) (snd y))
914+ indexedAndSorted = sortBy (\x y -> comp (snd x) (snd y))
916915 (mapWithIndex Tuple xs)
917916
918917-- | Remove the duplicates from an array, where element equality is determined
0 commit comments