Skip to main content

BinaryOperatorAggregate

Struct BinaryOperatorAggregate 

Source
pub struct BinaryOperatorAggregate<T, F>
where F: Fn(T, T) -> T + Send + Sync,
{ /* private fields */ }
Expand description

A channel that reduces values using a binary operator.

This channel maintains a single value and applies a reduction function when new values are written. This is useful for operations like summing, finding max/min, or any other associative binary operation.

§Example

use rust_langgraph::channels::{BaseChannel, BinaryOperatorAggregate};

// Sum reducer
let mut channel = BinaryOperatorAggregate::new(0, |a, b| a + b);
channel.update(vec![serde_json::json!(1), serde_json::json!(2), serde_json::json!(3)]).unwrap();
assert_eq!(channel.get().unwrap(), Some(serde_json::json!(6)));

Implementations§

Source§

impl<T, F> BinaryOperatorAggregate<T, F>
where T: Clone, F: Fn(T, T) -> T + Send + Sync + 'static,

Source

pub fn new(initial: T, reducer: F) -> Self

Create a new BinaryOperatorAggregate with an initial value and reducer

Source

pub fn value(&self) -> &T

Get a reference to the current value

Trait Implementations§

Source§

impl<T, F> BaseChannel for BinaryOperatorAggregate<T, F>
where T: Serialize + for<'de> Deserialize<'de> + Clone + Send + Sync + Debug + 'static, F: Fn(T, T) -> T + Send + Sync + 'static,

Source§

fn get(&self) -> Result<Option<Value>>

Get the current value as JSON
Source§

fn update(&mut self, values: Vec<Value>) -> Result<()>

Update the channel with new values Read more
Source§

fn checkpoint(&self) -> Result<Value>

Serialize the channel state for checkpointing
Source§

fn from_checkpoint(_data: Value) -> Result<Box<dyn BaseChannel>>

Restore the channel state from a checkpoint
Source§

fn type_name(&self) -> &'static str

Get the channel’s type name for debugging
Source§

fn is_empty(&self) -> bool

Check if the channel is empty
Source§

impl<T, F> Debug for BinaryOperatorAggregate<T, F>
where T: Debug, F: Fn(T, T) -> T + Send + Sync,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, F> Freeze for BinaryOperatorAggregate<T, F>
where T: Freeze,

§

impl<T, F> RefUnwindSafe for BinaryOperatorAggregate<T, F>

§

impl<T, F> Send for BinaryOperatorAggregate<T, F>
where T: Send,

§

impl<T, F> Sync for BinaryOperatorAggregate<T, F>
where T: Sync,

§

impl<T, F> Unpin for BinaryOperatorAggregate<T, F>
where T: Unpin,

§

impl<T, F> UnsafeUnpin for BinaryOperatorAggregate<T, F>
where T: UnsafeUnpin,

§

impl<T, F> UnwindSafe for BinaryOperatorAggregate<T, F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.