packages feed

ghcup-0.2.7.0 / lib / GHCup / Types / Optics.hs

{-# OPTIONS_GHC -Wno-orphans #-}{-# LANGUAGE AllowAmbiguousTypes #-}{-# LANGUAGE ConstraintKinds #-}{-# LANGUAGE DataKinds #-}{-# LANGUAGE DuplicateRecordFields #-}{-# LANGUAGE FlexibleContexts #-}{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE OverloadedStrings #-}{-# LANGUAGE TemplateHaskell #-}{-|Module      : GHCup.Types.OpticsDescription : GHCup opticsCopyright   : (c) Julian Ospald, 2020License     : LGPL-3.0Maintainer  : hasufell@hasufell.deStability   : experimentalPortability : portable-}module GHCup.Types.Optics whereimport GHCup.Typesimport Control.Monad.Readerimport Data.ByteString      ( ByteString )import Data.Map.Strict      ( Map )import Opticsimport URI.ByteStringimport qualified Data.Map.Strict as MmakePrisms ''ToolmakePrisms ''ArchitecturemakePrisms ''LinuxDistromakePrisms ''PlatformmakePrisms ''TagmakePrisms ''EnvUnionmakePrisms ''GHCupDownloadsmakePrisms ''ToolVersionSpecmakePrisms ''RevisionSpecmakePrisms ''ArchitectureSpecmakePrisms ''PlatformSpecmakePrisms ''PlatformVersionSpecmakePrisms ''RevmakeLenses ''ToolInfomakeLenses ''ToolDescriptionmakeLenses ''EnvSpecmakeLenses ''ConfigSpecmakeLenses ''MakeSpecmakeLenses ''InstallationSpecGenmakeLenses ''InstallMetadatamakeLenses ''PlatformResultmakeLenses ''DownloadInfomakeLenses ''TagmakeLenses ''VersionInfomakeLenses ''VersionMetadatamakeLenses ''TargetVersionReqmakeLenses ''TargetVersionRevmakeLenses ''InstallFileRulemakeLenses ''GHCupInfomakeLenses ''CapturedProcesstoolVersionsL :: Lens' ToolInfo (Map TargetVersion VersionMetadata)toolVersionsL = toolVersions % _ToolVersionSpecrevisionSpecL :: Getter VersionMetadata (Map Int VersionInfo)revisionSpecL = vmRevisionSpec % _RevisionSpec % to (M.mapKeys unRev)archL :: Lens' VersionInfo (MapIgnoreUnknownKeys Architecture PlatformSpec)archL = viArch % _ArchitectureSpecuriSchemeL' :: Lens' (URIRef Absolute) SchemeuriSchemeL' = lensVL uriSchemeLschemeBSL' :: Lens' Scheme ByteStringschemeBSL' = lensVL schemeBSLauthorityL' :: Lens' (URIRef a) (Maybe Authority)authorityL' = lensVL authorityLauthorityHostL' :: Lens' Authority HostauthorityHostL' = lensVL authorityHostLauthorityPortL' :: Lens' Authority (Maybe Port)authorityPortL' = lensVL authorityPortLportNumberL' :: Lens' Port IntportNumberL' = lensVL portNumberLhostBSL' :: Lens' Host ByteStringhostBSL' = lensVL hostBSLpathL' :: Lens' (URIRef a) ByteStringpathL' = lensVL pathLqueryL' :: Lens' (URIRef a) QueryqueryL' = lensVL queryLmapLast :: AffineFold (Map k a) (k, a)mapLast = to M.lookupMax % _JustixOrLast :: forall k v . Ord k => Maybe k -> AffineFold (Map k v) (k, v)ixOrLast = maybe mapLast (\i -> castOptic @An_AffineFold (ix @(Map k v) i) % to (i,))    ----------------------    --[ Lens utilities ]--    ----------------------gets :: forall f a env m . (MonadReader env m, LabelOptic' f A_Lens env a)     => m agets = asks (^. labelOptic @f)getAppState :: MonadReader AppState m => m AppStategetAppState = askgetLeanAppState :: ( MonadReader env m                   , LabelOptic' "settings"     A_Lens env Settings                   , LabelOptic' "dirs"         A_Lens env Dirs                   , LabelOptic' "keyBindings"  A_Lens env KeyBindings                   , LabelOptic' "loggerConfig" A_Lens env LoggerConfig                   , LabelOptic' "pfreq"        A_Lens env PlatformRequest                   )                => m LeanAppStategetLeanAppState = do  s <- gets @"settings"  d <- gets @"dirs"  k <- gets @"keyBindings"  p <- gets @"pfreq"  l <- gets @"loggerConfig"  pure (LeanAppState s d k p l)getSettings :: ( MonadReader env m               , LabelOptic' "settings" A_Lens env Settings               )            => m SettingsgetSettings = gets @"settings"getDirs :: ( MonadReader env m           , LabelOptic' "dirs" A_Lens env Dirs           )        => m DirsgetDirs = gets @"dirs"getLogCleanup :: ( MonadReader env m                 , LabelOptic' "logCleanup" A_Lens env (IO ())                 )              => m (IO ())getLogCleanup = gets @"logCleanup"getKeyBindings :: ( MonadReader env m                  , LabelOptic' "keyBindings" A_Lens env KeyBindings                  )               => m KeyBindingsgetKeyBindings = gets @"keyBindings"getGHCupInfo :: ( MonadReader env m                , LabelOptic' "ghcupInfo" A_Lens env GHCupInfo                )             => m GHCupInfogetGHCupInfo = gets @"ghcupInfo"getPlatformReq :: ( MonadReader env m                  , LabelOptic' "pfreq" A_Lens env PlatformRequest                  )               => m PlatformRequestgetPlatformReq = gets @"pfreq"type HasSettings env = (LabelOptic' "settings" A_Lens env Settings)type HasDirs env = (LabelOptic' "dirs" A_Lens env Dirs)type HasKeyBindings env = (LabelOptic' "keyBindings" A_Lens env KeyBindings)type HasGHCupInfo env = (LabelOptic' "ghcupInfo" A_Lens env GHCupInfo)type HasPlatformReq env = (LabelOptic' "pfreq" A_Lens env PlatformRequest)type HasLog env = (LabelOptic' "loggerConfig" A_Lens env LoggerConfig)getCache :: (MonadReader env m, HasSettings env) => m BoolgetCache = getSettings <&> cachegetDownloader :: (MonadReader env m, HasSettings env) => m DownloadergetDownloader = getSettings <&> downloaderinstance LabelOptic "dirs" A_Lens Dirs Dirs Dirs Dirs where  labelOptic = lens id (\_ d -> d)instance LabelOptic "loggerConfig" A_Lens LoggerConfig LoggerConfig LoggerConfig LoggerConfig where  labelOptic = lens id (\_ d -> d)