Files
RustAst/examples/pipeline_script_ticker.myc
T
Brummel 10a7fcb576 Refactor: Replace Object with StreamStorage for streams
The `Object` trait is too generic and has been causing confusion. This
commit introduces `StreamStorage` as a dedicated trait for reactive
stream types.

This change involves:

- Renaming `Object` to `StreamStorage` in relevant places.
- Updating the `Value::Object` enum variant to `Value::Stream`.
- Modifying how streams are handled in the compiler, VM, and tests to
  use the new `StreamStorage` trait.
- Adjusting example scripts and tests to reflect the change in type
  representation.
- The `StreamNode` struct now explicitly holds its `element_type`.
2026-03-29 18:01:46 +02:00

49 lines
1.1 KiB
Plaintext

;; Benchmark: 2.7us
;; Benchmark-Repeat: 749
(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
; Matches Rust: (rng.f64() - 0.5) * 2.0
(def change (* (- (random) 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)
)
)
)
(assert-eq :stream (type-of my_indicator))
)