Skip to main content

Fold

Trait Fold 

Source
pub trait Fold<L, S> {
    // Required methods
    fn initial(&self, context: &FoldContext) -> S;
    fn step(&self, state: S, entry: &L, context: &FoldContext) -> S;

    // Provided methods
    fn finalize(&self, state: S, _context: &FoldContext) -> S { ... }
    fn derive<'a, I>(&self, entries: I, context: &FoldContext) -> FoldOutcome<S>
       where Self: Sized,
             I: IntoIterator<Item = &'a L>,
             L: 'a { ... }
    fn derive_filtered<'a, I, F>(
        &self,
        entries: I,
        context: &FoldContext,
        filter: F,
    ) -> FoldOutcome<S>
       where Self: Sized,
             I: IntoIterator<Item = &'a L>,
             L: 'a,
             F: Fn(&L) -> bool { ... }
}
Expand description

Core fold trait for deriving state from entries.

A fold is the “measurement operator” that collapses a sequence of entries into a derived state. The fold is parameterized by:

  • L: The entry type (LogEntry, AtomEntry, MemoryEntry, etc.)
  • S: The derived state type

Folds are deterministic: same entries + same context = same state.

Required Methods§

Source

fn initial(&self, context: &FoldContext) -> S

Get the initial state before any entries are processed.

Source

fn step(&self, state: S, entry: &L, context: &FoldContext) -> S

Process a single entry and return the new state.

This is the core step function: state’ = step(state, entry, context)

Provided Methods§

Source

fn finalize(&self, state: S, _context: &FoldContext) -> S

Finalize the state after all entries are processed.

Default implementation returns state unchanged.

Source

fn derive<'a, I>(&self, entries: I, context: &FoldContext) -> FoldOutcome<S>
where Self: Sized, I: IntoIterator<Item = &'a L>, L: 'a,

Derive state from an iterator of entries.

This is the main entry point for using a fold.

Source

fn derive_filtered<'a, I, F>( &self, entries: I, context: &FoldContext, filter: F, ) -> FoldOutcome<S>
where Self: Sized, I: IntoIterator<Item = &'a L>, L: 'a, F: Fn(&L) -> bool,

Derive state with a filter.

Implementations on Foreign Types§

Source§

impl<L, S, T> Fold<L, S> for Box<T>
where T: Fold<L, S> + ?Sized,

Source§

fn initial(&self, context: &FoldContext) -> S

Source§

fn step(&self, state: S, entry: &L, context: &FoldContext) -> S

Source§

fn finalize(&self, state: S, context: &FoldContext) -> S

Source§

impl<L, S, T> Fold<L, S> for Arc<T>
where T: Fold<L, S> + ?Sized,

Source§

fn initial(&self, context: &FoldContext) -> S

Source§

fn step(&self, state: S, entry: &L, context: &FoldContext) -> S

Source§

fn finalize(&self, state: S, context: &FoldContext) -> S

Implementors§

Source§

impl<L1, L2, S, F, M> Fold<L1, S> for MapFold<L1, L2, S, F, M>
where F: Fold<L2, S>, M: Fn(&L1) -> L2,

Source§

impl<L> Fold<L, CommonFoldState> for CommonFold<L>

Source§

impl<L> Fold<L, bool> for AnyFold<L>

Source§

impl<L> Fold<L, i64> for SumI64Fold<L>

Source§

impl<L> Fold<L, usize> for CountFold<L>

Source§

impl<L> Fold<L, usize> for FilterCountFold<L>

Source§

impl<L, S, F, P> Fold<L, S> for FilterFold<L, S, F, P>
where F: Fold<L, S>, P: Fn(&L) -> bool,

Source§

impl<L, S, I, St, F> Fold<L, S> for FnFold<L, S, I, St, F>
where I: Fn(&FoldContext) -> S, St: Fn(S, &L, &FoldContext) -> S, F: Fn(S, &FoldContext) -> S,