module GhcDatabase
( newestGhcVersion
, ghcVersionsWithBaseIn
, newestGhcVersionIn
, baseVersionsIn
, newestBaseVersionIn
, baseVersionForGhc
) where
import Distribution.Version
import Data.Maybe (listToMaybe)
import Data.List (find)
import VabalContext
type GhcVersion = Version
type BaseVersion = Version
newestGhcVersion :: GhcToBaseMap -> GhcVersion
newestGhcVersion = ghcVersion . head . unwrapMap
isVersionInRange :: VersionRange -> Version -> Bool
isVersionInRange = flip withinRange
entriesWithBaseVersionIn :: GhcToBaseMap -> VersionRange -> [GhcMetadata]
entriesWithBaseVersionIn gtb vr =
filter (isVersionInRange vr . baseVersion) (unwrapMap gtb)
ghcVersionsWithBaseIn :: GhcToBaseMap -> VersionRange -> [GhcVersion]
ghcVersionsWithBaseIn gtb vr = ghcVersion <$> entriesWithBaseVersionIn gtb vr
newestGhcVersionIn :: GhcToBaseMap -> VersionRange -> Maybe GhcVersion
newestGhcVersionIn gtb = listToMaybe . ghcVersionsWithBaseIn gtb
baseVersionsIn :: GhcToBaseMap -> VersionRange -> [BaseVersion]
baseVersionsIn gtb vr = baseVersion <$> entriesWithBaseVersionIn gtb vr
newestBaseVersionIn :: GhcToBaseMap -> VersionRange -> Maybe BaseVersion
newestBaseVersionIn gtb = listToMaybe . baseVersionsIn gtb
baseVersionForGhc :: GhcToBaseMap -> GhcVersion -> Maybe BaseVersion
baseVersionForGhc gtb v = baseVersion <$> find ((v ==) . ghcVersion) (unwrapMap gtb)