1
1
mirror of https://github.com/github/semantic.git synced 2024-12-01 00:33:59 +03:00

📝 bind/bindAll.

This commit is contained in:
Rob Rix 2018-05-30 09:16:12 -04:00
parent 01b30e5ae1
commit dcf4b9abc7

View File

@ -51,9 +51,11 @@ withDefaultEnvironment e = local (const e)
lookupEnv :: (Member (Reader (Environment location)) effects, Member (State (Environment location)) effects) => Name -> Evaluator location value effects (Maybe (Address location value))
lookupEnv name = (<|>) <$> (fmap Address . Env.lookup name <$> getEnv) <*> (fmap Address . Env.lookup name <$> defaultEnvironment)
-- | Bind a 'Name' to an 'Address' in the current scope.
bind :: Member (State (Environment location)) effects => Name -> Address location value -> Evaluator location value effects ()
bind name = modifyEnv . Env.insert name . unAddress
-- | Bind all of the names from an 'Environment' in the current scope.
bindAll :: Member (State (Environment location)) effects => Environment location -> Evaluator location value effects ()
bindAll = foldr ((>>) . uncurry bind . second Address) (pure ()) . pairs