pub struct BoxConditionalBiTransformer<T, U, R> { /* private fields */ }Expand description
BoxConditionalBiTransformer struct
A conditional bi-transformer that only executes when a bi-predicate is
satisfied. Uses BoxBiTransformer and BoxBiPredicate for single
ownership semantics.
This type is typically created by calling BoxBiTransformer::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 bi-predicate returns
true - Chainable: Can add
or_elsebranch to create if-then-else logic - Implements BiTransformer: Can be used anywhere a
BiTransformeris expected
§Examples
§With or_else Branch
use prism3_function::{BiTransformer, BoxBiTransformer};
let add = BoxBiTransformer::new(|x: i32, y: i32| x + y);
let multiply = BoxBiTransformer::new(|x: i32, y: i32| x * y);
let conditional = add.when(|x: &i32, y: &i32| *x > 0).or_else(multiply);
assert_eq!(conditional.apply(5, 3), 8); // when branch executed
assert_eq!(conditional.apply(-5, 3), -15); // or_else branch executed§Author
Haixing Hu
Implementations§
Source§impl<T, U, R> BoxConditionalBiTransformer<T, U, R>where
T: 'static,
U: 'static,
R: 'static,
impl<T, U, R> BoxConditionalBiTransformer<T, U, R>where
T: 'static,
U: 'static,
R: 'static,
Sourcepub fn or_else<F>(self, else_transformer: F) -> BoxBiTransformer<T, U, R>where
F: BiTransformer<T, U, R> + 'static,
pub fn or_else<F>(self, else_transformer: F) -> BoxBiTransformer<T, U, R>where
F: BiTransformer<T, U, R> + 'static,
Trait Implementations§
Source§impl<T, U, R> Debug for BoxConditionalBiTransformer<T, U, R>
impl<T, U, R> Debug for BoxConditionalBiTransformer<T, U, R>
Auto Trait Implementations§
impl<T, U, R> Freeze for BoxConditionalBiTransformer<T, U, R>
impl<T, U, R> !RefUnwindSafe for BoxConditionalBiTransformer<T, U, R>
impl<T, U, R> !Send for BoxConditionalBiTransformer<T, U, R>
impl<T, U, R> !Sync for BoxConditionalBiTransformer<T, U, R>
impl<T, U, R> Unpin for BoxConditionalBiTransformer<T, U, R>
impl<T, U, R> !UnwindSafe for BoxConditionalBiTransformer<T, U, 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