mirror of
https://github.com/github/semantic.git
synced 2024-12-22 14:21:31 +03:00
ef696d3c41
This looks like a big patch, but it's very straightforward: no behavior has changed. After the umpteenth time spent hitting a compile error because I passed a `FilePath` rather than a `File` to `readBlobFromPath`, I decided to finally make the needed refactors to Semantic.IO, and to split off the `File` type and `Files` effect. This patch: * adds the `MonadIO` class to `Prologue`'s export list * moves `File` into `Data.File` * moves `Handle` into `Data.Handle` * moves `Files` into `Semantic.Task.Files` * moves functions for reading blobs into `Data.Blob` * keeps general IO helpers in Semantic.IO * renames `readFile` to `readBlobFromFile` * renames `readBlobFromPath` to `readBlobFromFile'` This should have a positive effect on compile times and ease of navigation throughout the codebase.
19 lines
719 B
Haskell
19 lines
719 B
Haskell
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
|
|
module Semantic.Env
|
|
( envLookupNum
|
|
, envLookupString
|
|
) where
|
|
|
|
import Prologue
|
|
import System.Environment
|
|
import Text.Read (readMaybe)
|
|
|
|
envLookupString :: MonadIO io => String -> String -> io String
|
|
envLookupString defaultVal k = liftIO $ fromMaybe defaultVal <$> lookupEnv k
|
|
|
|
-- | Although the `Num a` constraint is redundant (hence -Wno-redundant-constraints), we use this constraint to communicate this function is meant to read Num values.
|
|
envLookupNum :: (MonadIO io, Num a, Read a) => a -> String -> io a
|
|
envLookupNum defaultVal k = liftIO $ parse <$> lookupEnv k
|
|
where parse x | Just s <- x, Just p <- readMaybe s = p
|
|
| otherwise = defaultVal
|