You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LocSta provides composable, stateful stream blocks using F# computation expressions. Each block is a pure function that threads state automatically, making it easy to build complex signal processing pipelines — from simple counters to full audio DSP chains.
Core Concept
A SigStream<'v,'c,'s> is a function that takes a StateController and a context value, and returns a sequence of output values along with the updated state. The stream { } computation expression composes these blocks, automatically managing state allocation and threading. Streams can emit zero, one, or multiple values per tick using yield.
openLocSta.Core// A simple stateful stream: counter that increments by 1letmyCounter=
stream {let!state= useState 0letcurrent= state.Value
state.Value <- current +1return current
}// Evaluate 5 samples (context is unit here)letresult= myCounter |> Eval.run 5(fun _ ->())// result = [0; 1; 2; 3; 4]
Key Primitives
Primitive
Description
stream { }
Computation expression builder for composing streams
return / yield
Emit a single value (yield allows multi-emit with Combine)
yield!
Forward all values from a sub-stream
getCtx()
Read the current input/context value
useState value
Local mutable state, initialized once
useStateWith init
Local mutable state with lazy initializer
useMemoWith init
Memoized value (lazy, computed once)
ofSeq sequence
Create a stream from a sequence (emits empty when exhausted)
map proj stream
Transform stream output
Eval.run n getCtx stream
Evaluate n values with a context generator
Eval.runWith inputs stream
Evaluate with an input sequence
Eval.toSeq getCtx stream
Convert to a lazy seq<'v> (stops after 1000 silent ticks)
Eval.toSeqWith max getCtx stream
Same with custom silent-tick limit
Examples
Exponential Moving Average
openLocStaopenLocSta.Blocks.Statistics.Emaletinputs=[1.0;2.0;3.0;4.0;5.0]letresult= ema 0.5|> Eval.runWith inputs
// Smoothed output approaching the input signal