Update examples to use StreamNode and Series with lookback

The `PipelineNode` has been refactored into `StreamNode`. This commit
updates the example files to reflect this change and also updates the
`series` constructor to accept a lookback parameter.

The `PipelineNode` was an artifact of a previous implementation and is
no longer needed. The `StreamNode` is the appropriate type for
representing the output of a pipe operation.

The `series` function now requires a `lookback` argument to specify the
maximum number of items to store. This makes the behavior of series more
explicit and prevents accidental unbounded memory growth.
This commit is contained in:
Michael Schimmel
2026-03-07 23:48:09 +01:00
parent d08fab4f73
commit 595bcf09e5
15 changed files with 108 additions and 233 deletions
+22
View File
@@ -7,3 +7,25 @@
(do ~body (again))
)))
)
;; Creates a stateful cache (Series) from a stateless stream.
;;
;; Pipes are highly optimized, stateless stream-routers that do not allocate memory
;; for historical data. If multiple indicators need to read historical data from
;; a stream, or if you need to access previous items via index (e.g. `(my_data 5)`),
;; you must explicitly cache the stream.
;;
;; Parameters:
;; lookback: The maximum number of items to keep in memory (e.g. 100).
;; type: The data type or schema of the series (e.g. :float or {:price :float}).
;; src: The source stream to observe and cache.
;;
;; Returns:
;; A stateful Series object that automatically updates when the source stream fires.
(macro cache [lookback type src]
`(do
(def data (series ~lookback ~type))
(pipe [~src] (fn [s] (do (push data s))))
data
)
)