595bcf09e5
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.
49 lines
1.1 KiB
Plaintext
49 lines
1.1 KiB
Plaintext
;; Benchmark: 3.2us
|
|
;; Benchmark-Repeat: 613
|
|
;; Output: <StreamNode>
|
|
|
|
(do
|
|
;; Set the random seed to match the existing test output exactly
|
|
(def random (make-random 42))
|
|
|
|
;; Use our new generic create-ticker to pulse 3 times
|
|
(def cnt 3)
|
|
(def ticker (create-ticker (fn [] (> (assign cnt (- cnt 1)) -1))))
|
|
|
|
;; The candle generator reacting to the ticker
|
|
(def last-close 100.0)
|
|
|
|
(def src1
|
|
(pipe [ticker]
|
|
(fn [_]
|
|
(do
|
|
(def change (* (- (random) 0.5) 2.0)) ; Matches Rust: (rng.f64() - 0.5) * 2.0
|
|
(def open last-close)
|
|
(def high (+ open (abs (* (random) 2.0))))
|
|
(def low (- open (abs (* (random) 2.0))))
|
|
(assign last-close (+ open change))
|
|
{:open open :high high :low low :close last-close}
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
(def combined
|
|
(pipe [src1]
|
|
(fn [t1]
|
|
(.close t1)
|
|
)
|
|
)
|
|
)
|
|
|
|
(def my_indicator
|
|
(pipe [combined]
|
|
(fn [close_price]
|
|
(+ close_price 10.0)
|
|
)
|
|
)
|
|
)
|
|
|
|
my_indicator
|
|
)
|