Appearance
AlertPredicate
What it does
Consumer-side adapter that fires an AlertTick when a user-supplied predicate matches an analytic's emission. Composes with any typed row the callback delivers.
rust
// Cargo.toml:
// kairos = "0.1"
use kairos::{AlertPredicate, AlertTick, Client, GreeksRow};
let client = Client::connect(("me@example.com", "secret"))?;
// `AlertPredicate::new(closure)` constructs a value-typed predicate.
// Evaluate it against each row the `.on_event` callback delivers.
let predicate = AlertPredicate::new(|delta: &f64| delta.abs() > 0.5);
let sub = client
.live()
.greeks(["QQQ"])
.on_event(move |row: &GreeksRow| {
if predicate.evaluate(&row.delta) {
let _ = AlertTick { value: row.delta };
}
})?;
// ... later ...
sub.unsubscribe();API surface
| Method | Returns |
|---|---|
AlertPredicate::new(closure) | AlertPredicate<T> |
predicate.evaluate(&T) | bool |
The predicate is value-typed, not stream-typed. Composition is a consumer-side concern — drive the predicate inline in the .on_event callback or build an adapter type around it.
Replay parity
AlertPredicate is stateless — the underlying analytic's emission stream carries replay-parity by construction; the predicate is a pure function. Replay equivalence is preserved end-to-end.
Why a primitive
Cross-analytic alerting is a common downstream concern. The predicate adapter keeps the alerting vocabulary out of every individual analytic's spec and lets the consumer compose the same predicate shape against any output stream.