pub struct ArcConditionalStatefulTransformer<T, R> { /* private fields */ }Expand description
ArcConditionalStatefulTransformer struct
A thread-safe conditional transformer that only executes when a predicate
is satisfied. Uses ArcStatefulTransformer and ArcPredicate for shared
ownership across threads.
This type is typically created by calling ArcStatefulTransformer::when() and is
designed to work with the or_else() method to create if-then-else
logic.
§Features
- Shared Ownership: Cloneable via
Arc, multiple owners allowed - Thread-Safe: Implements
Send, safe for concurrent use - Conditional Execution: Only maps when predicate returns
true - Chainable: Can add
or_elsebranch to create if-then-else logic
§Examples
use prism3_function::{StatefulTransformer, ArcStatefulTransformer};
let mut transformer = ArcStatefulTransformer::new(|x: i32| x * 2)
.when(|x: &i32| *x > 0)
.or_else(|x: i32| -x);
let mut transformer_clone = transformer.clone();
assert_eq!(transformer.apply(5), 10);
assert_eq!(transformer_clone.apply(-5), 5);§Author
Haixing Hu
Implementations§
Source§impl<T, R> ArcConditionalStatefulTransformer<T, R>where
T: 'static,
R: 'static,
impl<T, R> ArcConditionalStatefulTransformer<T, R>where
T: 'static,
R: 'static,
Sourcepub fn or_else<F>(&self, else_transformer: F) -> ArcStatefulTransformer<T, R>
pub fn or_else<F>(&self, else_transformer: F) -> ArcStatefulTransformer<T, R>
Trait Implementations§
Source§impl<T, R> Clone for ArcConditionalStatefulTransformer<T, R>
impl<T, R> Clone for ArcConditionalStatefulTransformer<T, R>
Source§impl<T, R> Debug for ArcConditionalStatefulTransformer<T, R>
impl<T, R> Debug for ArcConditionalStatefulTransformer<T, R>
Auto Trait Implementations§
impl<T, R> Freeze for ArcConditionalStatefulTransformer<T, R>
impl<T, R> !RefUnwindSafe for ArcConditionalStatefulTransformer<T, R>
impl<T, R> Send for ArcConditionalStatefulTransformer<T, R>
impl<T, R> Sync for ArcConditionalStatefulTransformer<T, R>
impl<T, R> Unpin for ArcConditionalStatefulTransformer<T, R>
impl<T, R> !UnwindSafe for ArcConditionalStatefulTransformer<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