pub struct BoxConditionalTransformer<T, R> { /* private fields */ }Expand description
BoxConditionalTransformer struct
A conditional transformer that only executes when a predicate is satisfied.
Uses BoxTransformer and BoxPredicate for single ownership semantics.
This type is typically created by calling BoxTransformer::when() and is
designed to work with the or_else() method to create if-then-else logic.
§Features
- Single Ownership: Not cloneable, consumes
selfon use - Conditional Execution: Only transforms when predicate returns
true - Chainable: Can add
or_elsebranch to create if-then-else logic - Implements Transformer: Can be used anywhere a
Transformeris expected
§Examples
§With or_else Branch
use prism3_function::{Transformer, BoxTransformer};
let double = BoxTransformer::new(|x: i32| x * 2);
let negate = BoxTransformer::new(|x: i32| -x);
let conditional = double.when(|x: &i32| *x > 0).or_else(negate);
assert_eq!(conditional.apply(5), 10); // when branch executed
assert_eq!(conditional.apply(-5), 5); // or_else branch executed§Author
Haixing Hu
Implementations§
Source§impl<T, R> BoxConditionalTransformer<T, R>where
T: 'static,
R: 'static,
impl<T, R> BoxConditionalTransformer<T, R>where
T: 'static,
R: 'static,
Sourcepub fn or_else<F>(self, else_transformer: F) -> BoxTransformer<T, R>where
F: Transformer<T, R> + 'static,
pub fn or_else<F>(self, else_transformer: F) -> BoxTransformer<T, R>where
F: Transformer<T, R> + 'static,
Trait Implementations§
Source§impl<T, R> Debug for BoxConditionalTransformer<T, R>
impl<T, R> Debug for BoxConditionalTransformer<T, R>
Auto Trait Implementations§
impl<T, R> Freeze for BoxConditionalTransformer<T, R>
impl<T, R> !RefUnwindSafe for BoxConditionalTransformer<T, R>
impl<T, R> !Send for BoxConditionalTransformer<T, R>
impl<T, R> !Sync for BoxConditionalTransformer<T, R>
impl<T, R> Unpin for BoxConditionalTransformer<T, R>
impl<T, R> !UnwindSafe for BoxConditionalTransformer<T, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more