Skip to content

Commit

Permalink
Re #8392: extended haddocks of new utility hasElem
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasabel committed Aug 28, 2022
1 parent 1784dfb commit 76f6d3c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cabal-install/src/Distribution/Client/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,13 @@ safeRead s
| [(x, "")] <- reads s = Just x
| otherwise = Nothing


-- | @hasElem xs x = elem x xs@ except that @xs@ is turned into a 'Set' first.
-- Use underapplied to speed up subsequent lookups, e.g. @filter (hasElem xs) ys@.
-- Only amortized when used several times!
--
-- Time complexity \(O((n+m) \log(n))\) for \(m\) lookups in a list of length \(n\).
-- (Compare this to 'elem''s \(O(nm)\).)
--
-- This is [Agda.Utils.List.hasElem](https://hackage.haskell.org/package/Agda-2.6.2.2/docs/Agda-Utils-List.html#v:hasElem).
hasElem :: Ord a => [a] -> a -> Bool
hasElem xs = (`Set.member` Set.fromList xs)

0 comments on commit 76f6d3c

Please sign in to comment.