Repository F# setup
open System
open System.IO
open System.Threading
open System.Threading.Tasks
open Axial
open Axial.Layers
open Axial.Console
open Axial.FileSystem
open Axial.Hosting
open Axial.Hosting.Browser
open Axial.Hosting.Node
open Axial.PlatformService
open Axial.State
open Axial.Telemetry
open Axial.Telemetry.JavaScriptGetting Started
A stream pipeline has three parts:
- A source describes where values come from.
- Operators transform values one pull at a time.
- A terminal consumer turns the stream back into a
Flowthat can run.
> (FlowStream.fromSeq [ 1..10 ] : FlowStream<int>)
- |> FlowStream.filter (fun value -> value % 2 = 0)
- |> FlowStream.map (fun value -> value * 10)
- |> FlowStream.runFold (+) 0
- |> Flow.run ();;val it: Exit<int,Never> = Success 300Axial.FlowStreamModulefromSeq: 'value seq -> FlowStream<'env,'error,'value>Creates a stream from a synchronous sequence of values. The sequence of values to be emitted by the stream. A that yields each value from the sequence. FlowStream.fromSeq [1..10] |> FlowStream.runCollect |> Flow.run ()
(..): ^T -> ^T -> ^T seqThe standard overloaded range operator, e.g. [n..m] for lists, seq {n..m} for sequences The start value of the range. The end value of the range. The sequence spanning the range. [1..4] // Evaluates to [1; 2; 3; 4] [1.5..4.4] // Evaluates to [1.5; 2.5; 3.5] ['a'..'d'] // Evaluates to ['a'; 'b'; 'c'; 'd'] [|1..4|] // Evaluates to an array [|1; 2; 3; 4|] { 1..4 } // Evaluates to a sequence [1; 2; 3; 4])
FlowStreamA stream with no environment requirement and no typed failure.
intAn abbreviation for the CLI type . Basic Types
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
filter: ('a -> bool) -> FlowStream<'b,'c,'a> -> FlowStream<'b,'c,'a>Keeps values that satisfy a predicate. stream |> FlowStream.filter (fun value -> value > 0)
value: int(%): ^T1 -> ^T2 -> ^T3Overloaded modulo operator The first parameter. The second parameter. The result of the operation. 29 % 5 // Evaluates to 4
(=): 'T -> 'T -> boolStructural equality The first parameter. The second parameter. The result of the comparison. 5 = 5 // Evaluates to true 5 = 6 // Evaluates to false [1; 2] = [1; 2] // Evaluates to true (1, 5) = (1, 6) // Evaluates to false
map: ('v -> 'w) -> FlowStream<'env,'error,'v> -> FlowStream<'env,'error,'w>Transforms the successful values of a stream using the provided function. The function to transform each value. The stream whose values should be transformed. A new stream that yields transformed values. let stream = FlowStream.fromSeq [1; 2; 3] |> FlowStream.map (fun n -> n * 2)
(*): ^T1 -> ^T2 -> ^T3Overloaded multiplication operator The first parameter. The second parameter. The result of the operation. 8 * 6 // Evaluates to 48
runFold: ('state -> 'value -> 'state) -> 'state -> FlowStream<'env,'error,'value> -> Flow<'env,'error,'state>Folds a stream into one value inside Flow. stream |> FlowStream.runFold (+) 0
(+): ^T1 -> ^T2 -> ^T3Overloaded addition operator The first parameter. The second parameter. The result of the operation. 2 + 2 // Evaluates to 4 "Hello " + "World" // Evaluates to "Hello World"
Axial.Flowrun: 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs the workflow and blocks until the final exit is available. The environment used by the workflow. The workflow to run. The final workflow exit. let exit = workflow |> Flow.run environment
Constructing the pipeline does not enumerate the sequence. Flow.run starts the terminal Flow. FlowStream.runFold then pulls one
value at a time through filter and map, retaining only the running total.
Keep effects in Flow
Use FlowStream.mapFlow when transforming one value requires an effect:
> (FlowStream.fromSeq [ "a"; "b"; "c" ] : FlowStream<string>)
- |> FlowStream.mapFlow (fun letter -> Flow.succeed (letter.ToUpperInvariant()))
- |> FlowStream.runCollect
- |> Flow.run ();;val it: Exit<string list,Never> = Success ["A"; "B"; "C"]Axial.FlowStreamModulefromSeq: 'value seq -> FlowStream<'env,'error,'value>Creates a stream from a synchronous sequence of values. The sequence of values to be emitted by the stream. A that yields each value from the sequence. FlowStream.fromSeq [1..10] |> FlowStream.runCollect |> Flow.run ()
FlowStreamA stream with no environment requirement and no typed failure.
stringAn abbreviation for the CLI type . Basic Types
(|>): 'T1 -> ('T1 -> 'U) -> 'UApply a function to a value, the value being on the left, the function on the right The argument. The function. The function result. let doubleIt x = x * 2 3 |> doubleIt // Evaluates to 6
mapFlow: ('a -> Flow<'b,'c,'d>) -> FlowStream<'b,'c,'a> -> FlowStream<'b,'c,'d>Transforms every value with a Flow effect. ids |> FlowStream.mapFlow load
letter: stringAxial.Flowsucceed: 'value -> Flow<'env,'error,'value>Same as ok. The value to wrap in a successful flow. A flow that always succeeds with the provided value. let result = Flow.succeed 42 |> Flow.run () // result = Success 42
ToUpperInvariant: unit -> stringReturns a copy of this object converted to uppercase using the casing rules of the invariant culture. The uppercase equivalent of the current string.
runCollect: FlowStream<'a,'b,'c> -> Flow<'a,'b,'c list>Collects all emitted values into a list. stream |> FlowStream.runCollect
run: 'env -> Flow<'env,'error,'value> -> Exit<'value,'error>Runs the workflow and blocks until the final exit is available. The environment used by the workflow. The workflow to run. The final workflow exit. let exit = workflow |> Flow.run environment
A mapping failure stops further pulls and remains in the stream's typed error channel. Cancellation reaches the active operation through the enclosing Flow runtime.
Choose the terminal operation deliberately
FlowStream.runCollect is convenient for a known finite stream, but it stores every value. Prefer FlowStream.runFold, FlowStream.runForEach, or
FlowStream.runForEachFlow when values can be handled incrementally.
Terminal consumers create a child scope. Completion, failure, interruption, and early termination close stream-owned resources and child fibers before the terminal Flow returns.
Next, read Constructing streams.

