Skip to content

Commit

Permalink
keep first occurence when removing duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
dorchard committed Aug 23, 2024
1 parent d9ebee9 commit eb111e7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Language/Fortran/Analysis/ModGraph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ genModGraph mversion includeDirs cppOpts paths = do
pure ()
execStateT (mapM_ iter (removeDuplicates paths)) modGraph0

-- Remove duplicates from a list preserving the left most occurrence.
removeDuplicates :: Eq a => [a] -> [a]
removeDuplicates = foldl (\ acc x -> if x `elem` acc then acc else x : acc) []
removeDuplicates [] = []
removeDuplicates (x:xs) =
if x `elem` xs
then x : removeDuplicates (filter (/= x) xs)
else x : removeDuplicates xs

modGraphToDOT :: ModGraph -> String
modGraphToDOT ModGraph { mgGraph = gr } = unlines dot
Expand Down

0 comments on commit eb111e7

Please sign in to comment.