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.JavaScriptTesting
Supply fake environment values or replace layers at the execution boundary. Public examples use the same workflow shape as production code.
A first test is a fake environment record, one Flow.run, and one assertion — no HTTP or layers required:
Show page setup
// Setup for the checked example on this page.
open Axial
/// Fails the docs test when an example's result differs from the value shown.
let shouldEqual expected actual =
if actual <> expected then failwithf "Expected %A but got %A" expected actualtype UserLookup = { FindName: int -> string }
type UserEnv = { Lookup: UserLookup }
let findUserName (id: int) : Flow<UserEnv, Never, string> =
Flow.envWith (fun env -> env.Lookup.FindName id)
// The test supplies a fake environment; production supplies the real lookup.
let fakeEnv = { Lookup = { FindName = fun id -> if id = 42 then "Ada" else "unknown" } }
FsLiveDocsGeneratedPage0_6B7179067CFE.UserLookupFindName: int -> stringintAn abbreviation for the CLI type . Basic Types
stringAn abbreviation for the CLI type . Basic Types
FsLiveDocsGeneratedPage0_6B7179067CFE.UserEnvLookup: UserLookupfindUserName: int -> Flow<UserEnv,Never,string>id: intAxial.Flow`3Axial.NeverRepresents an error channel that cannot occur.
Axial.FlowenvWith: ('env -> 'value) -> Flow<'env,'error,'value>Projects one value from the current environment. This is the primary way to access app dependencies, configuration, or request metadata stored in env. The projection runs only when the flow is executed, so constructing the flow is still pure and side-effect free. Prefer small projections over passing a large environment deeper into reusable helpers. A function that extracts a value from the environment. A containing the projected value. let currentTime () = Flow.envWith (fun (environment: BaseRuntime) -> environment.Clock.UtcNow())
env: UserEnvfakeEnv: UserEnv(=): '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
Requires & types
Requires: open Axial (packages: Axial)val findUserName: int -> Flow<UserEnv,Never,string>val fakeEnv: UserEnvfindUserName 42 |> Flow.run fakeEnv |> shouldEqual (Exit.Success "Ada" : Exit<string, Never>)
findUserName 1 |> Flow.run fakeEnv |> shouldEqual (Exit.Success "unknown" : Exit<string, Never>)
findUserName: int -> Flow<UserEnv,Never,string>(|>): '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
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
fakeEnv: UserEnvshouldEqual: 'a -> 'a -> unitAxial.Exit`2Represents the final outcome of a workflow execution. The type of the success value. The type of the domain-specific failure value.
SuccessThe workflow completed successfully.
stringAn abbreviation for the CLI type . Basic Types
Axial.NeverRepresents an error channel that cannot occur.
Requires & types
Requires: open Axial (packages: Axial)
