use crate::{ selection::Selection, state::{EditorState, EvaluationResult}, }; pub enum EvaluationStrategy { Sequential, Grouped, } pub type MonadicState = (EditorState, EvaluationResult); pub struct EditorStateMonad { func: Box MonadicState>, } impl EditorStateMonad { pub fn new(f: impl Fn(EditorState) -> MonadicState + 'static) -> Self { Self { func: Box::new(f) } } pub fn run(&self, initial_state: EditorState) -> MonadicState { (self.func)(initial_state) } pub fn run_with_strategy( monads: Vec, strategy: EvaluationStrategy, initial_state: EditorState, ) -> Result { match strategy { EvaluationStrategy::Sequential => { let mut state_changes = Vec::new(); let mut last_selection = Selection::empty(); let mut current_state = initial_state; for monad in monads { let (new_state, (sel, st_ch)) = monad.run(current_state); current_state = new_state; last_selection = sel; state_changes.extend(st_ch); } Ok((current_state, (last_selection, state_changes))) } EvaluationStrategy::Grouped => { panic!("TODO") } } } }