use crate::{CausalEffectPropagationProcess, CausalityError, EffectLog, EffectValue};
pub trait CausalMonad: Sized {
type Value;
type State;
type Context;
fn pure(value: Self::Value) -> Self;
fn bind<NewValue, F>(
self,
f: F,
) -> CausalEffectPropagationProcess<
NewValue,
Self::State,
Self::Context,
CausalityError,
EffectLog,
>
where
F: FnOnce(
EffectValue<Self::Value>,
Self::State,
Option<Self::Context>,
) -> CausalEffectPropagationProcess<
NewValue,
Self::State,
Self::Context,
CausalityError,
EffectLog,
>;
}
impl<Value, State, Context> CausalMonad
for CausalEffectPropagationProcess<Value, State, Context, CausalityError, EffectLog>
where
State: Default,
{
type Value = Value;
type State = State;
type Context = Context;
fn pure(value: Value) -> Self {
Self {
value: EffectValue::Value(value),
state: State::default(),
context: None,
error: None,
logs: EffectLog::new(),
}
}
fn bind<NewValue, F>(
self,
f: F,
) -> CausalEffectPropagationProcess<NewValue, State, Context, CausalityError, EffectLog>
where
F: FnOnce(
EffectValue<Value>,
State,
Option<Context>,
) -> CausalEffectPropagationProcess<
NewValue,
State,
Context,
CausalityError,
EffectLog,
>,
{
self.bind(f)
}
}