From 1a109e4d6bcc348607859342b144daef11c124cd Mon Sep 17 00:00:00 2001 From: tslil Date: Wed, 22 Oct 2025 22:02:55 +0100 Subject: Implement the coniditional selection transformation --- rprt-engine/src/selection.rs | 9 --------- rprt-engine/src/selection_function.rs | 36 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/rprt-engine/src/selection.rs b/rprt-engine/src/selection.rs index ee83294..1d1c557 100644 --- a/rprt-engine/src/selection.rs +++ b/rprt-engine/src/selection.rs @@ -75,15 +75,6 @@ where SelectionError(SelectionError), } -impl From for VectoriseError -where - E: std::error::Error + 'static, -{ - fn from(e: E) -> Self { - VectoriseError::ProcessingError(e) - } -} - impl Selection { pub fn empty() -> Self { Self::MultiRanges { diff --git a/rprt-engine/src/selection_function.rs b/rprt-engine/src/selection_function.rs index 3da61c9..0b6e98e 100644 --- a/rprt-engine/src/selection_function.rs +++ b/rprt-engine/src/selection_function.rs @@ -47,7 +47,37 @@ impl From for SelectionFunction> { } impl SelectionFunction> { - pub fn empty() -> Self { + pub fn transform_conditional(sf: Self) -> Self { + fn condition( + pred: Result>, + res: Selection, + ) -> Result> { + match pred { + Ok(mut sel) => Ok(if sel.is_empty() { sel } else { res }), + Err(e) => Err(e), + } + } + + let dyadic: Option Result<_, _>>> = + if let Some(dyadic) = sf.dyadic { + Some(Box::new(move |es, left, right| { + condition((dyadic)(es, left, right), left.clone()) + })) + } else { + None + }; + + let monadic: Box Result<_, _>> = + Box::new(move |es, left| condition((sf.monadic)(es, left), left.clone())); + + SelectionFunction { + niladic: sf.niladic, + monadic, + dyadic, + } + } + // ---------------------------------------------------------------- + pub fn empty_sequential() -> Self { SFComponents { niladic: Box::new(|_| Ok(Selection::empty())), monadic_rank0: Box::new(|_, _, _| Ok(Selection::empty())), @@ -57,6 +87,10 @@ impl SelectionFunction> { .into() } + pub fn empy_structural() -> Self { + Self::empty_sequential() + } + pub fn end_sequential() -> Self { fn get_end_position(es: &EditorState, buffer_id: BufferID) -> Result { if let Some(buf) = es.get_buffer(buffer_id) { -- cgit v1.2.3