pub struct CausalEffectPropagationProcess<Value, State, Context, Error, Log> {
pub value: EffectValue<Value>,
pub state: State,
pub context: Option<Context>,
pub error: Option<Error>,
pub logs: Log,
}Expand description
The fundamental unit of causal computation in DeepCausality.
CausalEffectPropagationProcess encapsulates the state of a computation moving through a causal
graph. It unifies value propagation, state management, context awareness, error handling, and
comprehensive logging into a single, monadic structure.
§Concepts
- Value: The primary data being transformed (e.g., a signal, a decision).
- State: Persistent data that evolves as the process moves through the graph (Markovian state).
- Context: Read-only configuration or environment data available to all steps.
- Error: A failure state that short-circuits further computation but preserves logs.
- Logs: An append-only history of every step, essential for auditability and explainability.
§Rationale
In complex causal reasoning, it is not enough to just know the final result. We must know how that result was reached, what invalid states were encountered, and what context was active. This struct implements the Monad pattern to handle these concerns automatically, allowing users to focus on the domain logic (“Business Logic”) rather than plumbing (error checking, logging).
Fields§
§value: EffectValue<Value>The current value of the computation.
state: StateThe current state of the process (e.g., accumulated risk, counters).
context: Option<Context>The optional execution context (e.g., global config, reference data).
error: Option<Error>The current error state. If Some, new bind operations will skip execution.
logs: LogThe audit log containing the history of operations.
Implementations§
Source§impl<Value: Debug, Error: Debug, Log: Debug + Display + LogSize> CausalEffectPropagationProcess<Value, (), (), Error, Log>
impl<Value: Debug, Error: Debug, Log: Debug + Display + LogSize> CausalEffectPropagationProcess<Value, (), (), Error, Log>
Sourcepub fn explain(&self) -> String
pub fn explain(&self) -> String
Generates a human-readable explanation of the causal computation’s history.
This method iterates over the accumulated logs, providing a comprehensive history of the computation, including the final value and any errors.
§Returns
A String containing the formatted explanation.
Source§impl<Value, State, Context, Error, Log> CausalEffectPropagationProcess<Value, State, Context, Error, Log>
impl<Value, State, Context, Error, Log> CausalEffectPropagationProcess<Value, State, Context, Error, Log>
Source§impl<Value, Error, Log> CausalEffectPropagationProcess<Value, (), (), Error, Log>where
Log: LogSize,
impl<Value, Error, Log> CausalEffectPropagationProcess<Value, (), (), Error, Log>where
Log: LogSize,
Source§impl<Value, State, Context, Error, Log> CausalEffectPropagationProcess<Value, State, Context, Error, Log>
impl<Value, State, Context, Error, Log> CausalEffectPropagationProcess<Value, State, Context, Error, Log>
Sourcepub fn bind<F, NewValue>(
self,
f: F,
) -> CausalEffectPropagationProcess<NewValue, State, Context, Error, Log>where
F: FnOnce(EffectValue<Value>, State, Option<Context>) -> CausalEffectPropagationProcess<NewValue, State, Context, Error, Log>,
NewValue: Default,
pub fn bind<F, NewValue>(
self,
f: F,
) -> CausalEffectPropagationProcess<NewValue, State, Context, Error, Log>where
F: FnOnce(EffectValue<Value>, State, Option<Context>) -> CausalEffectPropagationProcess<NewValue, State, Context, Error, Log>,
NewValue: Default,
Chains a stateful, context-aware computation.
This is the primary method for building Markovian process chains, as the
function f receives the value, state, and context from the previous step.
Source§impl<Value, State, Context, Error, Log> CausalEffectPropagationProcess<Value, State, Context, Error, Log>
impl<Value, State, Context, Error, Log> CausalEffectPropagationProcess<Value, State, Context, Error, Log>
Sourcepub fn with_state(
effect: CausalEffectPropagationProcess<Value, (), (), Error, Log>,
initial_state: State,
initial_context: Option<Context>,
) -> Self
pub fn with_state( effect: CausalEffectPropagationProcess<Value, (), (), Error, Log>, initial_state: State, initial_context: Option<Context>, ) -> Self
Lifts a stateless effect into a stateful process by providing an initial state and context.
This is the primary entry point for starting a stateful computation chain from a simple, pre-existing effect.
§Arguments
effect: The statelessPropagatingEffect(where State and Context are()).initial_state: The starting state for the new process.initial_context: The optional starting context for the new process.
§Returns
A new CausalEffectPropagationProcess ready for stateful operations.
Source§impl<Value, State, Context> CausalEffectPropagationProcess<Value, State, Context, CausalityError, EffectLog>
impl<Value, State, Context> CausalEffectPropagationProcess<Value, State, Context, CausalityError, EffectLog>
Sourcepub fn from_error(err: CausalityError) -> Self
pub fn from_error(err: CausalityError) -> Self
Creates a new process that explicitly contains an error. The state is set to default.
Sourcepub fn none() -> Self
pub fn none() -> Self
Creates a new process with EffectValue::None, default state, and no error.
Sourcepub fn from_effect_value(effect_value: EffectValue<Value>) -> Self
pub fn from_effect_value(effect_value: EffectValue<Value>) -> Self
Creates a new process from a given EffectValue.
The state is set to default.
pub fn from_value(value: Value) -> Self
Sourcepub fn from_effect_value_with_log(
value: EffectValue<Value>,
logs: EffectLog,
) -> Self
pub fn from_effect_value_with_log( value: EffectValue<Value>, logs: EffectLog, ) -> Self
Creates a new process from a given EffectValue and EffectLog.
The state is set to default.
pub fn from_value_with_log(value: Value, logs: EffectLog) -> Self
Source§impl<Value, State, Context, Log> CausalEffectPropagationProcess<Value, State, Context, CausalityError, Log>
impl<Value, State, Context, Log> CausalEffectPropagationProcess<Value, State, Context, CausalityError, Log>
Sourcepub fn bind_or_error<F, NewValue>(
self,
f: F,
err_msg: &str,
) -> CausalEffectPropagationProcess<NewValue, State, Context, CausalityError, Log>where
F: FnOnce(Value, State, Option<Context>) -> CausalEffectPropagationProcess<NewValue, State, Context, CausalityError, Log>,
NewValue: Default,
pub fn bind_or_error<F, NewValue>(
self,
f: F,
err_msg: &str,
) -> CausalEffectPropagationProcess<NewValue, State, Context, CausalityError, Log>where
F: FnOnce(Value, State, Option<Context>) -> CausalEffectPropagationProcess<NewValue, State, Context, CausalityError, Log>,
NewValue: Default,
Chains a computation while automatically unwrapping the inner EffectValue.
If the EffectValue is None, this method short-circuits with a CausalityError
containing the provided err_msg. This simplifies the common pattern of:
bind -> match effect_value { Some(v) => f(v), None => Error }
Trait Implementations§
Source§impl<Value: Clone, State: Clone, Context: Clone, Error: Clone, Log: Clone> Clone for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
impl<Value: Clone, State: Clone, Context: Clone, Error: Clone, Log: Clone> Clone for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
Source§fn clone(
&self,
) -> CausalEffectPropagationProcess<Value, State, Context, Error, Log>
fn clone( &self, ) -> CausalEffectPropagationProcess<Value, State, Context, Error, Log>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Value: Debug, State: Debug, Context: Debug, Error: Debug, Log: Debug> Debug for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
impl<Value: Debug, State: Debug, Context: Debug, Error: Debug, Log: Debug> Debug for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
Source§impl<Value: Debug, Error: Debug, Log: Debug> Display for CausalEffectPropagationProcess<Value, (), (), Error, Log>
impl<Value: Debug, Error: Debug, Log: Debug> Display for CausalEffectPropagationProcess<Value, (), (), Error, Log>
Source§impl<Value, State, Context, Error, Log> Intervenable<Value> for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
impl<Value, State, Context, Error, Log> Intervenable<Value> for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
Source§impl<Value: PartialEq, State: PartialEq, Context: PartialEq, Error: PartialEq, Log: PartialEq> PartialEq for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
impl<Value: PartialEq, State: PartialEq, Context: PartialEq, Error: PartialEq, Log: PartialEq> PartialEq for CausalEffectPropagationProcess<Value, State, Context, Error, Log>
Source§fn eq(
&self,
other: &CausalEffectPropagationProcess<Value, State, Context, Error, Log>,
) -> bool
fn eq( &self, other: &CausalEffectPropagationProcess<Value, State, Context, Error, Log>, ) -> bool
self and other values to be equal, and is used by ==.