Skip to content

make nubByEq more efficient, part of #71 #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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