Skip to main content

Crate florecon

Crate florecon 

Source
Expand description

florecon — two dual conservation laws over accounting data.

The same ledger is read two ways, and florecon is the algebra for each:

The two are duals — partition by identity vs. couple by value — and share one stance: no privileged numeraire. Every number is a closure over the caller’s own payload, so multi-currency is just different closures, and there is no pivot, no original, no magic field.

// reconcile: an opposite-and-equal pair collapses to one group.
use florecon::strategy::*;

#[derive(Clone)]
struct Tx { amount: i64 }

let s = exact_1to1(|_: &Entry<Tx>| Some(0), |e| e.amount);
let r = s.run(vec![Entry::new(1, Tx { amount: 100 }), Entry::new(2, Tx { amount: -100 })]);
assert_eq!(r.groups.len(), 1);
assert_eq!(r.groups[0].size(), 2);
// allocate: rent pushed onto products by revenue, penny-exact.
use florecon::alloc::*;

let rent = Measure::build(&["geog"], &[(&[("geog", 1)], 1000)]);
let rev = Measure::build(&["geog", "product"], &[
    (&[("geog", 1), ("product", 10)], 30),
    (&[("geog", 1), ("product", 11)], 70),
]);
let a = rent.allocate(&rev);
assert_eq!(a.total(), rent.total()); // value conserved
assert_eq!(a.get(&Key::of(&[("geog", 1), ("product", 10)])), 300);

Re-exports§

pub use strategy::Entry;
pub use strategy::FlowSpec;
pub use strategy::Group;
pub use strategy::Id;
pub use strategy::Resolution;
pub use strategy::Strategy;

Modules§

alloc
allocation as coupling — the dual of crate::strategy.
strategy
The strategy algebra: parse a bag of entries into a partition of groups.
token