From ab61f684ee11863a0c5f555ba09149578ab085a3 Mon Sep 17 00:00:00 2001 From: sharno Date: Sun, 10 Feb 2019 20:20:19 -0500 Subject: [PATCH 1/2] make nubByEq more efficient, part of #71 --- src/Data/Array.purs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Data/Array.purs b/src/Data/Array.purs index d1359565..9f6a518b 100644 --- a/src/Data/Array.purs +++ b/src/Data/Array.purs @@ -926,10 +926,12 @@ nubBy comp xs = case head indexedAndSorted of -- | ``` -- | nubByEq :: forall a. (a -> a -> Boolean) -> Array a -> Array a -nubByEq eq xs = - case uncons xs of - Just o -> o.head : nubByEq eq (filter (\y -> not (o.head `eq` y)) o.tail) - Nothing -> [] +nubByEq eq xs = ST.run do + arr <- STA.unsafeThaw [] + ST.foreach xs \x -> do + e <- not <<< Exports.any (_ `eq` x) <$> (STA.unsafeFreeze arr) + when e $ void $ STA.push x arr + STA.unsafeFreeze arr -- | Calculate the union of two arrays. Note that duplicates in the first array -- | are preserved while duplicates in the second array are removed. From 8e90603587ba472591cac81baefc4fec96a62a49 Mon Sep 17 00:00:00 2001 From: Mohamed Elsharnouby Date: Mon, 11 Feb 2019 21:08:49 -0500 Subject: [PATCH 2/2] change `unsafeThaw []` to `empty` --- src/Data/Array.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/Array.purs b/src/Data/Array.purs index 9f6a518b..6349418a 100644 --- a/src/Data/Array.purs +++ b/src/Data/Array.purs @@ -927,7 +927,7 @@ nubBy comp xs = case head indexedAndSorted of -- | nubByEq :: forall a. (a -> a -> Boolean) -> Array a -> Array a nubByEq eq xs = ST.run do - arr <- STA.unsafeThaw [] + arr <- STA.empty ST.foreach xs \x -> do e <- not <<< Exports.any (_ `eq` x) <$> (STA.unsafeFreeze arr) when e $ void $ STA.push x arr