diff options
author | stuebinm | 2024-06-06 18:26:42 +0200 |
---|---|---|
committer | stuebinm | 2024-06-06 18:26:42 +0200 |
commit | 4321bb0b5b90c0f92217ccd07a67f17fce44b388 (patch) | |
tree | 5fbfd686f329b943d8d6462b9191a6a738a2770c /src/Conftrack/Source.hs | |
parent | d1446a8435a3cf06371eb6d4ebe25d6491612f4d (diff) |
nested values, tests, and aeson
Diffstat (limited to 'src/Conftrack/Source.hs')
-rw-r--r-- | src/Conftrack/Source.hs | 37 |
1 files changed, 7 insertions, 30 deletions
diff --git a/src/Conftrack/Source.hs b/src/Conftrack/Source.hs index df6f82c..ecfa20d 100644 --- a/src/Conftrack/Source.hs +++ b/src/Conftrack/Source.hs @@ -3,44 +3,21 @@ {-# LANGUAGE ImpredicativeTypes #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE AllowAmbiguousTypes #-} -{-# LANGUAGE OverloadedStrings #-} -module Conftrack.Source (ConfigSource(..), SomeSource(..), Trivial(..)) where +module Conftrack.Source (ConfigSource(..), SomeSource(..)) where -import Conftrack.Value (Key, Value(..), ConfigError(..), Origin) +import Conftrack.Value (Key, Value(..), ConfigError(..)) -import Control.Monad.State (get, modify, StateT (..), MonadState (..)) -import Data.Map.Strict (Map) -import qualified Data.Map.Strict as M -import Data.Function ((&)) +import Control.Monad.State (StateT (..)) import Data.Text (Text) -import qualified Data.Text as T class ConfigSource s where - type ConfigState s - fetchValue :: Key -> s -> StateT (ConfigState s) IO (Either ConfigError (Value, Text)) - leftovers :: s -> StateT (ConfigState s) IO (Maybe [Key]) + type SourceState s + fetchValue :: Key -> s -> StateT (SourceState s) IO (Either ConfigError (Value, Text)) + leftovers :: s -> StateT (SourceState s) IO (Maybe [Key]) data SomeSource = forall source. ConfigSource source - => SomeSource (source, ConfigState source) + => SomeSource (source, SourceState source) -newtype Trivial = Trivial (Map Key Value) - -instance ConfigSource Trivial where - type ConfigState Trivial = [Key] - fetchValue key (Trivial tree) = do - case M.lookup key tree of - Nothing -> pure $ Left NotPresent - Just val -> do - modify (key :) - pure $ Right (val, "Trivial source with keys "<> T.pack (show (M.keys tree))) - - leftovers (Trivial tree) = do - used <- get - - M.keys tree - & filter (`notElem` used) - & Just - & pure |