-module(evaluation_context). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([empty_evaluation_context/0, get_attribute/2, get_all_attributes/1, merge/2]). -export_type([evaluation_context/0]). -type evaluation_context() :: {evaluation_context, gleam@option:option(binary()), gleam@dict:dict(binary(), gleam@dynamic:dynamic_())}. -spec empty_evaluation_context() -> evaluation_context(). empty_evaluation_context() -> {evaluation_context, none, gleam@dict:new()}. -spec get_attribute(evaluation_context(), binary()) -> {ok, gleam@dynamic:dynamic_()} | {error, nil}. get_attribute(Evaluation_context, Key) -> gleam@dict:get(erlang:element(3, Evaluation_context), Key). -spec get_all_attributes(evaluation_context()) -> list({binary(), gleam@dynamic:dynamic_()}). get_all_attributes(Evaluation_context) -> maps:to_list(erlang:element(3, Evaluation_context)). -spec merge(evaluation_context(), evaluation_context()) -> evaluation_context(). merge(Initial_context, Overriding_context) -> Targeting_key = case erlang:element(2, Overriding_context) of none -> erlang:element(2, Initial_context); {some, _} -> erlang:element(2, Overriding_context) end, Attributes = gleam@dict:combine( erlang:element(3, Initial_context), erlang:element(3, Overriding_context), fun(_, Overriding) -> Overriding end ), {evaluation_context, Targeting_key, Attributes}.