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
A `SigStream<'v,'c,'s>` is a function that takes a `StateController` and a context value, and returns an output value along with the updated state. The `stream { }` computation expression composes these blocks, automatically managing state allocation and threading.
21
+
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`.
22
22
23
23
```fsharp
24
24
open LocSta.Core
@@ -42,15 +42,18 @@ let result = myCounter |> Eval.run 5 (fun _ -> ())
42
42
| Primitive | Description |
43
43
|---|---|
44
44
|`stream { }`| Computation expression builder for composing streams |
45
+
|`return` / `yield`| Emit a single value (`yield` allows multi-emit with `Combine`) |
46
+
|`yield!`| Forward all values from a sub-stream |
45
47
|`getCtx()`| Read the current input/context value |
46
48
|`useState value`| Local mutable state, initialized once |
47
49
|`useStateWith init`| Local mutable state with lazy initializer |
48
50
|`useMemoWith init`| Memoized value (lazy, computed once) |
49
-
|`ofSeq sequence`| Create a stream from a sequence |
51
+
|`ofSeq sequence`| Create a stream from a sequence (emits empty when exhausted) |
50
52
|`map proj stream`| Transform stream output |
51
-
|`Eval.run n getCtx stream`| Evaluate n samples with a context generator |
53
+
|`Eval.run n getCtx stream`| Evaluate n values with a context generator |
52
54
|`Eval.runWith inputs stream`| Evaluate with an input sequence |
53
-
|`Eval.toSeq getCtx stream`| Convert to an infinite `seq<'v>`|
55
+
|`Eval.toSeq getCtx stream`| Convert to a lazy `seq<'v>` (stops after 1000 silent ticks) |
56
+
|`Eval.toSeqWith max getCtx stream`| Same with custom silent-tick limit |
54
57
55
58
## Examples
56
59
@@ -212,6 +215,85 @@ let result = countWhere (fun x -> x > 4) |> Eval.runWith inputs
0 commit comments