Skip to content

Commit c7f3edd

Browse files
committed
Tags feature: replace some clumsy code
1 parent 66e7c9e commit c7f3edd

File tree

1 file changed

+5
-9
lines changed
  • src/Distribution/Server/Features/Tags

1 file changed

+5
-9
lines changed

src/Distribution/Server/Features/Tags/State.hs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import Control.Monad (liftM2)
2020
import Data.SafeCopy (base, deriveSafeCopy)
2121
import Data.Typeable (Typeable)
2222
import qualified Data.Char as Char
23+
import Data.Functor ( (<&>) )
2324
import Data.Maybe (fromMaybe)
24-
import Data.List (foldl')
25+
import Data.List (find, foldl')
2526
import Control.Monad.State (get, put, modify)
2627
import Control.Monad.Reader (ask, asks)
2728
import Control.DeepSeq
@@ -87,13 +88,9 @@ lookupTagAlias tag
8788
return (Map.lookup tag m)
8889

8990
getTagAlias :: Tag -> Query TagAlias Tag
90-
getTagAlias tag
91-
= do TagAlias m <- ask
92-
if tag `elem` Map.keys m
93-
then return tag
94-
else if tag `Set.member` foldr Set.union Set.empty (Map.elems m)
95-
then return $ head (Map.keys $ Map.filter (tag `Set.member`) m)
96-
else return tag
91+
getTagAlias tag = ask <&> \ (TagAlias m) ->
92+
if Map.member tag m then tag
93+
else maybe tag fst $ find (Set.member tag . snd) $ Map.toList m
9794

9895
emptyPackageTags :: PackageTags
9996
emptyPackageTags = PackageTags Map.empty Map.empty Map.empty
@@ -279,4 +276,3 @@ $(makeAcidic ''PackageTags ['tagsForPackage
279276
,'lookupReviewTags
280277
,'clearReviewTags
281278
])
282-

0 commit comments

Comments
 (0)