diff options
| author | tslil <tslil@posteo.de> | 2025-10-22 22:02:55 +0100 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2025-10-22 22:15:18 +0100 |
| commit | 1a109e4d6bcc348607859342b144daef11c124cd (patch) | |
| tree | be4e1fca2ce05860b3fe2af97e53ebc346e5fa62 /rprt-engine/src/selection_function.rs | |
| parent | 20674aa65148558fb849eb1bb9c8a5e4a0cf483d (diff) | |
Implement the coniditional selection transformation
Diffstat (limited to 'rprt-engine/src/selection_function.rs')
| -rw-r--r-- | rprt-engine/src/selection_function.rs | 36 |
1 files changed, 35 insertions, 1 deletions
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<SFComponents> for SelectionFunction<VectoriseError<SFError>> { } impl SelectionFunction<VectoriseError<SFError>> { - pub fn empty() -> Self { + pub fn transform_conditional(sf: Self) -> Self { + fn condition( + pred: Result<Selection, VectoriseError<SFError>>, + res: Selection, + ) -> Result<Selection, VectoriseError<SFError>> { + match pred { + Ok(mut sel) => Ok(if sel.is_empty() { sel } else { res }), + Err(e) => Err(e), + } + } + + let dyadic: Option<Box<dyn Fn(&EditorState, &Selection, &Selection) -> 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<dyn Fn(&EditorState, &Selection) -> 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<VectoriseError<SFError>> { .into() } + pub fn empy_structural() -> Self { + Self::empty_sequential() + } + pub fn end_sequential() -> Self { fn get_end_position(es: &EditorState, buffer_id: BufferID) -> Result<Selection, SFError> { if let Some(buf) = es.get_buffer(buffer_id) { |
