Skip to content

Commit

Permalink
Merge pull request #154 from sharno/nubByEq
Browse files Browse the repository at this point in the history
make nubByEq more efficient, part of #71
  • Loading branch information
garyb committed Mar 31, 2019
2 parents d218f6f + 8e90603 commit 83c2148
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Data/Array.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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.empty
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.
Expand Down

0 comments on commit 83c2148

Please sign in to comment.