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