pub struct Reducer<V> { /* private fields */ }Expand description
A channel that applies a reducer function to combine values.
Unlike LastValue, this channel can accept multiple values during
a single super-step and will combine them using the specified reducer.
§Type Parameters
V: The value type stored in this channel.
§Examples
ⓘ
use regula_core::channel::{Reducer, ReducerType, Channel};
// Create a reducer channel that appends to a vector
let mut channel: Reducer<Vec<String>> = Reducer::new(ReducerType::Append, None);
// Multiple updates are combined
channel.update(vec![vec!["a".to_string()]]).unwrap();
channel.update(vec![vec!["b".to_string()]]).unwrap();
// Result: ["a", "b"]Implementations§
Source§impl<V> Reducer<V>
impl<V> Reducer<V>
Sourcepub fn new(reducer_type: ReducerType, initial: Option<V>) -> Self
pub fn new(reducer_type: ReducerType, initial: Option<V>) -> Self
Create a new Reducer channel with the specified reducer type.
Sourcepub fn with_custom(reducer_fn: ReducerFn<V>, initial: Option<V>) -> Self
pub fn with_custom(reducer_fn: ReducerFn<V>, initial: Option<V>) -> Self
Create a new Reducer channel with a custom reducer function.
Sourcepub fn reducer_type(&self) -> &ReducerType
pub fn reducer_type(&self) -> &ReducerType
Get the reducer type.
Trait Implementations§
Source§impl<T> Channel for Reducer<Vec<T>>
impl<T> Channel for Reducer<Vec<T>>
Auto Trait Implementations§
impl<V> !RefUnwindSafe for Reducer<V>
impl<V> !UnwindSafe for Reducer<V>
impl<V> Freeze for Reducer<V>
impl<V> Send for Reducer<V>
impl<V> Sync for Reducer<V>
impl<V> Unpin for Reducer<V>
impl<V> UnsafeUnpin for Reducer<V>where
Option<V>: UnsafeUnpin,
Option<Arc<dyn Fn(V, V) -> V + Send + Sync>>: UnsafeUnpin,
PhantomData<V>: UnsafeUnpin,
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