aboutsummaryrefslogtreecommitdiff
path: root/rprt-engine/src/monad.rs
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2026-03-21 17:56:08 +0000
committertslil <tslil@posteo.de>2026-03-21 20:09:34 +0000
commit89d299376c97a3f866dccc15321713ce955d8125 (patch)
tree122bde2e89120bbe21f594e4209f47c9fc0fa352 /rprt-engine/src/monad.rs
parentfb0d0b91bfd45d1911e993ca753d81da5e60f60c (diff)
think the commit logic is worked out now for eager commits
Diffstat (limited to 'rprt-engine/src/monad.rs')
-rw-r--r--rprt-engine/src/monad.rs75
1 files changed, 0 insertions, 75 deletions
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<SelectionError> for MonadError {
- fn from(err: SelectionError) -> Self {
- MonadError::Selection(err)
- }
-}
-
-impl From<GroupedChangeError> for MonadError {
- fn from(err: GroupedChangeError) -> Self {
- MonadError::GroupedChange(err)
- }
-}
-
-pub struct EditorStateMonad {
- func: Box<dyn Fn(&EditorState) -> 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<EditorStateMonad>,
- strategy: EvaluationStrategy,
- state: &mut EditorState,
- ) -> Result<Selection, MonadError> {
- 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)?)
- }
- }
- }
-}