From 89d299376c97a3f866dccc15321713ce955d8125 Mon Sep 17 00:00:00 2001 From: tslil Date: Sat, 21 Mar 2026 17:56:08 +0000 Subject: think the commit logic is worked out now for eager commits --- rprt-engine/src/monad.rs | 75 ------------------------------------------------ 1 file changed, 75 deletions(-) delete mode 100644 rprt-engine/src/monad.rs (limited to 'rprt-engine/src/monad.rs') diff --git a/rprt-engine/src/monad.rs b/rprt-engine/src/monad.rs deleted file mode 100644 index ac35722..0000000 --- a/rprt-engine/src/monad.rs +++ /dev/null @@ -1,75 +0,0 @@ -use crate::{ - selection::{Selection, SelectionError}, - state::{EditorState, GroupedChangeError, StateResult}, -}; - -pub enum EvaluationStrategy { - Sequential, - Grouped, -} - -#[derive(Debug)] -pub enum MonadError { - Selection(SelectionError), - GroupedChange(GroupedChangeError), -} - -impl From for MonadError { - fn from(err: SelectionError) -> Self { - MonadError::Selection(err) - } -} - -impl From for MonadError { - fn from(err: GroupedChangeError) -> Self { - MonadError::GroupedChange(err) - } -} - -pub struct EditorStateMonad { - func: Box StateResult>, -} - -impl EditorStateMonad { - pub fn new(f: impl Fn(&EditorState) -> StateResult + 'static) -> Self { - Self { func: Box::new(f) } - } - - pub fn run(&self, state: &EditorState) -> StateResult { - (self.func)(state) - } - - pub fn run_with_strategy( - monads: Vec, - strategy: EvaluationStrategy, - state: &mut EditorState, - ) -> Result { - match strategy { - EvaluationStrategy::Sequential => { - let mut last_selection = Selection::empty(); - - for monad in monads { - let (sel, state_changes) = monad.run(state); - state.commit_changes(state_changes); - last_selection = sel; - } - - Ok(last_selection) - } - EvaluationStrategy::Grouped => { - let mut arms = Vec::new(); - let mut all_selections = Vec::new(); - - for monad in monads { - let (sel, state_changes) = monad.run(state); - all_selections.push(sel); - arms.push(state_changes); - } - - state.commit_changes_grouped(arms)?; - - Ok(Selection::union(all_selections)?) - } - } - } -} -- cgit v1.2.3