Skip to content

Replace expensive unique-like implementations #11861

@philderbeast

Description

@philderbeast

uniqueNames = length allExplanationIdStrings == length (nub allExplanationIdStrings)

Spotted by @Bodigrim when reviewing #11825. Please see the thread starting with #11825 (comment) for more detail.

Functions to check and mentioned in that thread are the above and the following;

hasNoDups :: Ord a => [a] -> Bool
hasNoDups = loop Set.empty
where
loop _ [] = True
loop s (x:xs) | s' <- Set.insert x s, Set.size s' > Set.size s
= loop s' xs
| otherwise
= False

listUnique :: Ord a => [a] -> Bool
listUnique xs =
let sorted = sort xs
in nub sorted == xs

isSorted :: Ord a => [a] -> Bool
isSorted (x1 : xs@(x2 : _)) = x1 <= x2 && isSorted xs
isSorted _ = True

allEqual :: Eq a => [a] -> Bool
allEqual xs = length (nub xs) == 1

allEqual :: Eq a => [a] -> Bool
allEqual [] = True
allEqual [_] = True
allEqual (x:y:ys) = x == y && allEqual (y:ys)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions