Skip to content

Commit 9be60e2

Browse files
committed
0.12 updates for ordNub patch
1 parent b085256 commit 9be60e2

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Data/Array.purs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ import Prelude
120120
import Control.Alt ((<|>))
121121
import Control.Alternative (class Alternative)
122122
import Control.Lazy (class Lazy, defer)
123-
import Control.Monad.Eff (foreachE)
124123
import Control.Monad.Rec.Class (class MonadRec, Step(..), tailRecM2)
125124
import Control.Monad.ST as ST
126125
import Data.Array.ST as STA
@@ -131,7 +130,7 @@ import Data.Foldable (foldl, foldr, foldMap, fold, intercalate, elem, notElem, f
131130
import Data.Maybe (Maybe(..), maybe, isJust, fromJust)
132131
import Data.Traversable (scanl, scanr) as Exports
133132
import Data.Traversable (sequence, traverse)
134-
import Data.Tuple (Tuple(..), fst, snd, uncurry)
133+
import Data.Tuple (Tuple(..), fst, snd)
135134
import Data.Unfoldable (class Unfoldable, unfoldr)
136135
import Partial.Unsafe (unsafePartial)
137136
import Unsafe.Coerce (unsafeCoerce)
@@ -903,16 +902,16 @@ nubEq = nubByEq eq
903902
nubBy :: forall a. (a -> a -> Ordering) -> Array a -> Array a
904903
nubBy 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

Comments
 (0)