Expand description
khive-fold: Cognitive primitives — Fold, Anchor, Objective, Selector.
Four cognitive primitives that form the “paper-folding” operation:
- Fold:
entries → derived state(deterministic reduce) - Anchor: causal graph traversal (provenance chains)
- Objective: score candidates and select best
- Selector: budget-constrained pack (many → subset)
Plus deterministic ordering primitives, composition combinators, and common strategies (Recency, Relevance, Weighted, etc.).
§Quick Start
use khive_fold::{fold_fn, Fold, FoldContext};
let counter = fold_fn(
|_ctx| 0usize,
|count, _entry: &i32, _ctx| count + 1,
);
let entries = [1, 2, 3, 4, 5];
let result = counter.derive(entries.iter(), &FoldContext::new());
assert_eq!(result.state, 5);Re-exports§
pub use anchor::Anchor;pub use anchor::AnchorGraph;pub use anchor::AnchorRef;pub use anchor::BfsAnchor;pub use selector::GreedySelector;pub use selector::Selector;pub use selector::SelectorInput;pub use selector::SelectorOutput;pub use selector::SelectorWeights;pub use objective::builtin::FirstMatchObjective;pub use objective::builtin::HasImportance;pub use objective::builtin::HasTimestamp;pub use objective::builtin::ImportanceObjective;pub use objective::builtin::MaxScoreObjective;pub use objective::builtin::RecencyObjective;pub use objective::builtin::RelevanceObjective;pub use objective::builtin::ThresholdObjective;pub use objective::compose::ConsensusObjective;pub use objective::compose::NegateObjective;pub use objective::compose::PriorityObjective;pub use objective::compose::ScaleObjective;pub use objective::compose::UnionObjective;pub use objective::compose::WeightedObjective;pub use objective::error::ObjectiveError;pub use objective::error::ObjectiveResult;pub use objective::objective_fn;pub use objective::DeterministicObjective;pub use objective::Objective;pub use objective::ObjectiveContext;pub use objective::Selection;pub use ordering::canonical_f32;pub use ordering::canonical_f64;pub use ordering::cmp_asc_score_then_id;pub use ordering::cmp_desc_score_then_id;pub use ordering::HasId;pub use ordering::ScoredEntry;
Modules§
- anchor
- Anchor: causal structure.
- objective
- Objective function framework — scoring, selection, composition.
- ordering
- Deterministic ordering primitives for objective functions
- selector
- Selector: many → subset under budget.
Structs§
- AnyFold
- A zero-allocation existential fold with a function-pointer predicate.
- Count
Fold - A zero-allocation count fold.
- Deterministic
Score - Dual
Fold - Dual fold — run two folds independently over the same entries.
- Filter
Count Fold - A zero-allocation count fold with a function-pointer predicate.
- Filter
Fold - Filter fold — only process entries matching a predicate.
- FnFold
- Helper to create a fold from closures.
- Fold
Context - Context for fold operations.
- Fold
Outcome - Outcome of a fold operation.
- MapFold
- Map fold — transform entries before folding.
- Quant
Key - 8-byte packed sort key: i32 quantized score + u32 ID prefix.
- Ranked
- Ranked item: score descending, ID ascending for ties.
- Sequential
Fold - Sequential fold — run one fold, then use its output to inform another.
- Shared
Json - Shared JSON value backed by
Arc<serde_json::Value>. - SumI64
Fold - A zero-allocation i64 summation fold with a function-pointer projection.
Enums§
- Common
Fold - Enum-dispatch fold for common patterns that would otherwise use
Box<dyn Fold>. - Common
Fold State - Unified state returned by
CommonFold. - Fold
Error - Errors that can occur in fold operations
- Fold
Failure - Failure returned by fallible fold operations.
Traits§
- Fold
- Core fold trait for deriving state from entries.
- TryFold
- Fallible fold step API for reducers that can reject invalid state shapes.
Functions§
- cmp_
asc_ then_ id - Compare scores ascending, lower ID wins ties.
- cmp_
desc_ then_ id - Compare scores descending, lower ID wins ties.
- filter
- Helper to create a filter fold.
- fold_fn
- Create a fold from just initial and step functions (no finalize).
- map
- Helper to create a map fold.
Type Aliases§
- Boxed
Fold - A boxed fold for dynamic dispatch.
- Fold
Result - Result type for fold operations
- Fold
Result Type - Result type for fold operations