Skip to content

Commit

Permalink
Discontinue using partial functions from Data.List
Browse files Browse the repository at this point in the history
  • Loading branch information
neilmayhew committed Mar 16, 2024
1 parent 88776e3 commit c495dc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions DependencyRoots.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ putRoots fRoots fShow = mapM_ (putStrLn . fShow) . sortForest . fRoots . makeGra
graphRoots :: Gr a b -> Forest a
graphRoots g = map labelAlts alternates
where forest = dff (topsort g) g
alternates = map (ancestors . rootLabel) forest
ancestors n = head $ rdff [n] g
alternates = concatMap (ancestors . rootLabel) forest
ancestors n = take 1 $ rdff [n] g
labelAlts = fmap (fromJust . lab g)

graphForest :: Gr a b -> Forest a
Expand All @@ -77,7 +77,7 @@ graphForest g = map labelTree forest

makeGraph :: [[String]] -> Gr String ()
makeGraph deps = fst $ mkMapGraph nodes edges
where nodes = map head deps
where nodes = concatMap (take 1) deps
edges = concatMap mkEdges deps
mkEdges (n : sucs) = map (n,, ()) sucs
mkEdges _ = error "Empty deps"
Expand Down Expand Up @@ -115,5 +115,5 @@ pkgDeps :: Package -> [String]
pkgDeps p = names "Depends" ++ names "Recommends"
where field = B.unpack . fromMaybe B.empty . flip fieldValue p
rels = fromRight [] . parseRelations . field
names = map (relName . head) . rels
names = concatMap (map relName . take 1) . rels
relName (Rel name _ _) = unBinPkgName name
26 changes: 13 additions & 13 deletions RepoList.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ import Data.Ord
import Data.List
( (\\)
, find
, groupBy
, intercalate
, isPrefixOf
, minimumBy
, nub
, nubBy
, sort
, sortBy
, sortOn
)
import Data.Maybe
import Data.Either
import Data.Function
import Network.Curl.Opts
import Numeric
Expand All @@ -37,6 +34,7 @@ import qualified Codec.Compression.GZip as GZip
import qualified Crypto.Hash.MD5 as MD5
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as LB
import qualified Data.List.NonEmpty as NE

import Network.Curl.Download
import Network.Curl.Download.Lazy
Expand Down Expand Up @@ -123,9 +121,9 @@ getSuite mirror suite uComponents uArches = do
getReleaseParts m s = do
let location = m </> "dists" </> s </> "Release"
releaseData <- readURI location
let release = head . unControl <$> parseControl location releaseData
components = fromRight [] $ words . fieldValue' "Components" <$> release
arches = fromRight [] $ words . fieldValue' "Architectures" <$> release
let release = either (const []) unControl $ parseControl location releaseData
components = words . fieldValue' "Components" =<< release
arches = words . fieldValue' "Architectures" =<< release
return (components, arches ++ ["source"])
where
fieldValue' name = maybe "" B.unpack . fieldValue name
Expand Down Expand Up @@ -268,7 +266,7 @@ checkPackageVersions suites insts = do
, checkInconsistentArches
, checkDecreasingVersions ]
errors = concatMap ($ insts) checks
name = pkgName . instPkg $ head insts
name = maybe "unknown" (pkgName . instPkg) $ listToMaybe insts
maintainers = nub . map (pkgMaintainer . instPkg) $ insts
unless (null errors) $ do
hPutStrLn stderr $ printf "%s: %s" name (intercalate ", " maintainers)
Expand All @@ -281,7 +279,9 @@ checkMissingSuites :: [Suite] -> [PkgInstance] -> [VersionError]
checkMissingSuites suites insts =
-- Present in all later suites after the first
let inSuites = nub . sort . map instSuite $ insts
missingFrom = dropWhile (/= head inSuites) suites \\ inSuites
missingFrom = case inSuites of
(s : _) -> dropWhile (/= s) suites \\ inSuites
_ -> []
in [MissingSuites missingFrom | not $ null missingFrom]

checkMultipleComponents :: [PkgInstance] -> [VersionError]
Expand All @@ -305,7 +305,7 @@ checkInconsistentArches insts =
&& (v1 `isPrefixOf` v2
|| v1 == v2
&& (fromMaybe "" r1 `isPrefixOf` fromMaybe "" r2))
in [InconsistentArches $ map (instSuite . head) problems | not $ null problems]
in [InconsistentArches $ concatMap (map instSuite . take 1) problems | not $ null problems]

checkDecreasingVersions :: [PkgInstance] -> [VersionError]
checkDecreasingVersions insts =
Expand All @@ -325,11 +325,11 @@ disordersBy :: (a -> a -> Bool) -> [a] -> [(a, a)]
disordersBy rel xs = filter (not . uncurry rel) $ zip xs (drop 1 xs)

groupSortBy :: Ord b => (a -> b) -> [a] -> [[a]]
groupSortBy field = groupBy ((==) `on` field) . sortOn field
groupSortBy field = map NE.toList . NE.groupAllWith field

combineAssocs :: Ord a => [(a, b)] -> [(a, [b])]
combineAssocs = map combine . groupSortBy fst
where combine g = (fst . head $ g, map snd g)
combineAssocs = map combine . NE.groupAllWith fst
where combine g = (fst $ NE.head g, NE.toList $ NE.map snd g)

pkgCompare :: Package -> Package -> Ordering
pkgCompare p1 p2 =
Expand Down Expand Up @@ -405,7 +405,7 @@ showVersion = show . prettyDebianVersion
showHexBytes :: B.ByteString -> String -> String
showHexBytes bs s = foldr showHexByte s (B.unpack bs)
showHexByte :: Enum a => a -> String -> [Char]
showHexByte b = tail . showHex (0x100 + fromEnum b)
showHexByte b = drop 1 . showHex (0x100 + fromEnum b)

split :: Eq a => a -> [a] -> [[a]]
split _ [] = []
Expand Down

0 comments on commit c495dc8

Please sign in to comment.