module Config.Read(readFilesConfig) where import Config.Type import Config.Haskell import Config.Yaml import Data.List.Extra import System.FilePath readFilesConfig :: [(FilePath, Maybe String)] -> IO [Setting] readFilesConfig :: [(FilePath, Maybe FilePath)] -> IO [Setting] readFilesConfig files :: [(FilePath, Maybe FilePath)] files = do [ConfigYaml] yaml <- ((FilePath, Maybe FilePath) -> IO ConfigYaml) -> [(FilePath, Maybe FilePath)] -> IO [ConfigYaml] forall (t :: * -> *) (m :: * -> *) a b. (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) mapM ((FilePath -> Maybe FilePath -> IO ConfigYaml) -> (FilePath, Maybe FilePath) -> IO ConfigYaml forall a b c. (a -> b -> c) -> (a, b) -> c uncurry FilePath -> Maybe FilePath -> IO ConfigYaml readFileConfigYaml) [(FilePath, Maybe FilePath)] yaml [[Setting]] haskell <- ((FilePath, Maybe FilePath) -> IO [Setting]) -> [(FilePath, Maybe FilePath)] -> IO [[Setting]] forall (t :: * -> *) (m :: * -> *) a b. (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b) mapM ((FilePath -> Maybe FilePath -> IO [Setting]) -> (FilePath, Maybe FilePath) -> IO [Setting] forall a b c. (a -> b -> c) -> (a, b) -> c uncurry FilePath -> Maybe FilePath -> IO [Setting] readFileConfigHaskell) [(FilePath, Maybe FilePath)] haskell [Setting] -> IO [Setting] forall (m :: * -> *) a. Monad m => a -> m a return ([Setting] -> IO [Setting]) -> [Setting] -> IO [Setting] forall a b. (a -> b) -> a -> b $ [[Setting]] -> [Setting] forall (t :: * -> *) a. Foldable t => t [a] -> [a] concat [[Setting]] haskell [Setting] -> [Setting] -> [Setting] forall a. [a] -> [a] -> [a] ++ [ConfigYaml] -> [Setting] settingsFromConfigYaml [ConfigYaml] yaml where (yaml :: [(FilePath, Maybe FilePath)] yaml, haskell :: [(FilePath, Maybe FilePath)] haskell) = ((FilePath, Maybe FilePath) -> Bool) -> [(FilePath, Maybe FilePath)] -> ([(FilePath, Maybe FilePath)], [(FilePath, Maybe FilePath)]) forall a. (a -> Bool) -> [a] -> ([a], [a]) partition (\(x :: FilePath x,_) -> FilePath -> FilePath lower (FilePath -> FilePath takeExtension FilePath x) FilePath -> [FilePath] -> Bool forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool `elem` [".yml",".yaml"]) [(FilePath, Maybe FilePath)] files