synplexum/examples/product.l1

50 lines
942 B
Text

// Product tracker: accumulates quantity and total cost from purchase events.
//
// Each step, a purchase of 3 units at price 7 arrives.
// The actor multiplies price * quantity to get the line cost,
// then adds it to the running total.
//
// After 4 steps:
// count = 4 * 3 = 12
// total = 4 * (7 * 3) = 84
// emitted values: [21, 42, 63, 84]
actor ledger {
state {
count: u64 = 0
total: u64 = 0
}
window summary : (count, total)
readers(report)
on Purchase(price: u64, qty: u64) {
count = count + qty
total = total + (price * qty)
}
}
leaf buy {
process {
forward(ledger, Purchase(7, 3))
}
}
leaf report {
reads ledger.summary
process {
read(ledger.summary.total)
emit(total)
}
}
pipeline main {
buy -> ledger -> report
}
core main {
actors: [ledger]
leaves: [buy, report]
pipelines: [main]
steps: 4
}