summaryrefslogtreecommitdiff
path: root/src/Language/Fiddle/Internal/Scopes.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Language/Fiddle/Internal/Scopes.hs')
-rw-r--r--src/Language/Fiddle/Internal/Scopes.hs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/Language/Fiddle/Internal/Scopes.hs b/src/Language/Fiddle/Internal/Scopes.hs
index 83ea144..eea4c6f 100644
--- a/src/Language/Fiddle/Internal/Scopes.hs
+++ b/src/Language/Fiddle/Internal/Scopes.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE DeriveFoldable #-}
+
module Language.Fiddle.Internal.Scopes where
import Control.Monad (forM)
@@ -14,7 +16,7 @@ data Scope k v = Scope
{ subScopes :: Map k (Scope k v), -- Nested sub-scopes
scopeValues :: Map k v -- Values stored in the current scope
}
- deriving (Eq, Ord, Show, Read)
+ deriving (Eq, Ord, Show, Read, Functor, Foldable)
-- | 'ScopePath' keeps track of the current scope path as a list of keys,
-- and also includes any additional paths (like imported modules or
@@ -50,7 +52,7 @@ instance Monoid (ScopePath k) where
-- final key is replaced, and the original value is returned in the result.
-- If the key path does not exist, it is created. The function returns a tuple
-- containing the previous value (if any) and the updated scope.
---
+--
-- This function effectively performs an "insert-or-update" operation, allowing
-- you to upsert values into nested scopes while tracking any existing value
-- that was replaced.
@@ -65,7 +67,6 @@ upsertScope (s :| (a : as)) v (Scope ss sv) =
-- insertScope :: (Ord k) => NonEmpty k -> t -> Scope k t -> Scope k t
-- insertScope a b = snd . upsertScope a b
-
-- | 'lookupScope' performs a lookup of a value in the scope using a key path
-- ('NonEmpty k'). It traverses through sub-scopes as defined by the path.
lookupScope :: (Ord k) => NonEmpty k -> Scope k t -> Maybe t