Commit 5bc5fb7f authored by Duncan Coutts's avatar Duncan Coutts

Add PackageIndex.delete

We occasionally need to remove packages from an index
eg to restrict the choices of a dependency resolver.
parent 80caca50
......@@ -22,6 +22,7 @@ module Distribution.Simple.PackageIndex (
-- * Updates
merge,
insert,
delete,
-- * Queries
......@@ -143,7 +144,7 @@ merge i1@(PackageIndex m1) i2@(PackageIndex m2) =
mergeBuckets :: Package pkg => [pkg] -> [pkg] -> [pkg]
mergeBuckets pkgs1 pkgs2 = stripDups (pkgs2 ++ pkgs1)
-- | Insert's a single package into the index.
-- | Inserts a single package into the index.
--
-- This is equivalent to (but slightly quicker than) using 'mappend' or
-- 'merge' with a singleton index.
......@@ -153,6 +154,18 @@ insert pkg (PackageIndex index) = PackageIndex $
let key = (lowercase . packageName) pkg
in Map.insertWith (flip mergeBuckets) key [pkg] index
-- | Removes a single package from the index.
--
delete :: Package pkg => PackageIdentifier -> PackageIndex pkg -> PackageIndex pkg
delete pkgid (PackageIndex index) = PackageIndex $
let key = (lowercase . packageName) pkgid
in Map.update filterBucket key index
where
filterBucket = deleteEmptyBucket
. filter (\pkg -> packageId pkg /= pkgid)
deleteEmptyBucket [] = Nothing
deleteEmptyBucket remaining = Just remaining
-- | Get all the packages from the index.
--
allPackages :: Package pkg => PackageIndex pkg -> [pkg]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment