FlowModule
PackageAxial
Summary
| Name | Signature | Synopsis |
|---|---|---|
| addFinalizerAsync | addFinalizerAsync finalizer | Registers a F# async finalizer with the current runtime scope on .NET or Fable. |
| ofExit | ofExit exit | Creates a flow from an execution outcome. |
| addFinalizer | addFinalizer finalizer | Registers an asynchronous finalizer with the current runtime scope. |
| addDisposable | addDisposable resource | Registers a disposable resource with the current runtime scope. |
| addAsyncDisposable | addAsyncDisposable resource | Registers an asynchronously disposable resource with the current runtime scope. |
| acquireRelease | acquireRelease acquire release | Acquires a resource and registers its release with the current runtime scope. |
| acquireReleaseWith | acquireReleaseWith acquire release useResource | Acquires a resource, uses it, and always runs the release action. |
| fromAsync | fromAsync operation | Creates a flow from a raw async operation. |
| fromAsyncResult | fromAsyncResult operation | Creates a flow from an async operation whose Error enters the typed error channel. |
| attemptAsync | attemptAsync operation | Creates a flow from an async operation and treats thrown exceptions as recoverable typed errors. |
| fromTask | fromTask factory | Creates a flow from a cancellable task factory. |
| fromTaskResult | fromTaskResult factory | Creates a flow from a cold task factory whose Error enters the typed error channel. |
| attemptTask | attemptTask factory | Creates a flow from a cancellable task factory and treats thrown exceptions as recoverable typed errors. |
| fromValueTask | fromValueTask factory | Creates a flow from a cancellable value-task factory. |
| fromValueTaskResult | fromValueTaskResult factory | Creates a flow from a cold value-task factory whose Error enters the typed error channel. |
| attemptValueTask | attemptValueTask factory | Creates a flow from a cancellable value-task factory and treats thrown exceptions as recoverable typed errors. |
| awaitStartedTask | awaitStartedTask startedTask | Observes a task that has already been started. |
| awaitStartedTaskResult | awaitStartedTaskResult startedTask | Observes an already-started task whose Error enters the typed error channel. |
| attemptStartedTask | attemptStartedTask startedTask | Observes a task that has already been started and treats thrown exceptions as recoverable typed errors. |
| awaitStartedValueTask | awaitStartedValueTask startedValueTask | Observes a value task that has already been started. |
| awaitStartedValueTaskResult | awaitStartedValueTaskResult startedValueTask | Observes an already-started value task whose Error enters the typed error channel. |
| attemptStartedValueTask | attemptStartedValueTask startedValueTask | Observes a value task that has already been started and treats thrown exceptions as recoverable typed errors. |
| ok | ok value | Creates a successful synchronous flow. |
| succeed | succeed value | Alias for ok that reads well in some call sites. |
| value | value item | Alias for ok that reads well in some call sites. |
| error | error failure | Creates a failing synchronous flow. |
| fail | fail failure | Alias for error that reads well in some call sites. |
| die | die exn | Creates a defective flow that fails with an exception. |
| fromResult | fromResult result | Lifts a into a synchronous flow. |
| verify | verify policy input | Creates a flow that verifies an input with an environment-aware policy. |
| withFiberObserver | withFiberObserver observer flow | Installs runtime fiber-lifecycle hooks for diagnostics and telemetry. |
| addFiberObserver | addFiberObserver observer flow | Adds runtime fiber-lifecycle hooks, composing with any observer already installed. |
| withFiberRegistry | withFiberRegistry registry flow | Tracks every fiber forked inside the flow in registry. |
| withAnnotationSink | withAnnotationSink sink flow | Installs a runtime annotation sink for integration packages. |
| addAnnotationSink | addAnnotationSink sink flow | Adds a runtime annotation sink, composing with any sink already installed. |
| annotate | annotate name value flow | Adds a runtime annotation for the duration of the supplied flow. |
| traceId | traceId traceId flow | Adds the standard trace_id runtime annotation for the duration of the supplied flow. |
| fork | fork flow | Starts a flow in a new fiber without waiting for it to complete. |
| forkNamed | forkNamed name flow | Starts a flow in a new fiber carrying a diagnostic name. |
| forkDetached | forkDetached flow | Starts a flow in a new fiber that is deliberately never awaited. |
| join | join fiber | Waits for a fiber to complete and returns its successful value or typed failure. |
| interrupt | interrupt fiber | Signals a fiber to stop and waits for it to finish its cleanup. |
| zipPar | zipPar left right | Combines two flows into a tuple of their values, running them concurrently. |
| race | race left right | Runs two flows concurrently and returns the result of the first one to complete. |
| fromOption | fromOption error value | Lifts an option into a synchronous flow with the supplied error. |
| fromValueOption | fromValueOption error value | Lifts a value option into a synchronous flow with the supplied error. |
| orElseFlow | orElseFlow errorFlow result | Attaches an environment-derived error to a result that failed without one. |
| env | env | Reads the current environment as the successful flow value. |
| envWith | envWith projection | Projects one value from the current environment. |
| map | map mapper flow | Transforms the successful value of a flow. |
| ignore | ignore flow | Maps the successful value of a synchronous flow to unit. |
| bind | bind binder flow | Sequences a dependent flow after a successful value. |
| (>>=) | flow >>= binder | Sequences a synchronous continuation after a successful value. |
| tap | tap binder flow | Runs an effect on success and preserves the original value. |
| tapError | tapError binder flow | Runs a synchronous side effect on failure and preserves the original error. |
| mapError | mapError mapper flow | Maps the error value of a synchronous flow. |
| tracedError | tracedError trace flow | Attaches diagnostic trace text to any failure cause of the flow. |
| mapBoth | mapBoth onSuccess onFailure flow | Maps both the successful value and the failure cause of a synchronous flow. |
| fold | fold onSuccess onFailure flow | Folds both the successful value and the failure cause into a new flow. |
| catch | catch handler flow | Catches exceptions raised during execution and simple defect outcomes, then maps them to a typed error. |
| orElseWith | orElseWith fallback flow | Computes a fallback flow from the typed error when the source flow fails. |
| orElse | orElse fallback flow | Falls back to another flow when the source flow fails. |
| zip | zip left right | Runs two flows sequentially and combines their successful values into a tuple. |
| map2 | map2 mapper left right | Combines two flows with a mapping function. |
| apply | apply flow value | Applies a flow-wrapped function to a flow-wrapped value. |
| map3 | map3 mapper left middle right | Combines three flows with a mapping function. |
| (<!>) | mapper flow | Maps the successful value of a synchronous flow. |
| (<*>) | flow <*> value | Applies a flow-wrapped function to a flow-wrapped value. |
| localEnv | localEnv mapping flow | Runs a flow against an environment derived from the outer environment. |
| delay | delay factory | Defers flow construction until execution time. |
| traverse | traverse mapping values | Transforms a sequence of values into a flow and stops at the first failure. |
| sequence | sequence flows | Transforms a sequence of flows into a flow of a sequence and stops at the first failure. |
| toAsync | toAsync environment flow | Builds a cold async that runs the workflow when it is started. |
| startTask | startTask environment flow | Starts the workflow immediately and returns a task handle for its final exit. |
| run | run environment flow | Runs the workflow and blocks until the final exit is available. |
Registers a F# async finalizer with the current runtime scope on .NET or Fable.
Parameters
| Name | Type | Description |
|---|---|---|
| finalizer | CancellationToken -> Async<unit> |
Returns
Flow<'env, 'error, unit>
Verification Examples
Flow.addFinalizerAsync (fun _ -> async { resource.Close() })Creates a flow from an execution outcome.
Parameters
| Name | Type | Description |
|---|---|---|
| exit | Exit<'value, 'error> |
Returns
Flow<'env, 'error, 'value>
Registers an asynchronous finalizer with the current runtime scope.
Parameters
| Name | Type | Description |
|---|---|---|
| finalizer | CancellationToken -> Task | The finalizer to run when the current scope closes. |
Returns
Flow<'env, 'error, unit>
Registers a disposable resource with the current runtime scope.
Parameters
| Name | Type | Description |
|---|---|---|
| resource | IDisposable | The disposable resource to close when the current scope closes. |
Returns
Flow<'env, 'error, unit>
Registers an asynchronously disposable resource with the current runtime scope.
Parameters
| Name | Type | Description |
|---|---|---|
| resource | IAsyncDisposable | The async disposable resource to close when the current scope closes. |
Returns
Flow<'env, 'error, unit>
Acquires a resource and registers its release with the current runtime scope.
Parameters
| Name | Type | Description |
|---|---|---|
| acquire | Flow<'env, 'error, 'resource> | The flow that acquires the resource. |
| release | 'resource -> CancellationToken -> Task | The release action to run when the current scope closes. |
Returns
Flow<'env, 'error, 'resource>
Acquires a resource, uses it, and always runs the release action.
Parameters
| Name | Type | Description |
|---|---|---|
| acquire | Flow<'env, 'error, 'resource> | The flow that acquires the resource. |
| release | 'resource -> CancellationToken -> Task | The release action to run after the resource is used. |
| useResource | 'resource -> Flow<'env, 'error, 'value> | The flow that uses the acquired resource. |
Returns
Flow<'env, 'error, 'value>
Creates a flow from a raw async operation.
Parameters
| Name | Type | Description |
|---|---|---|
| operation | Async<'value> |
Returns
Flow<'env, 'error, 'value>
Creates a flow from an async operation whose
Error enters the typed error channel.Parameters
| Name | Type | Description |
|---|---|---|
| operation | Async<Result<'value, 'error>> |
Returns
Flow<'env, 'error, 'value>
Creates a flow from an async operation and treats thrown exceptions as recoverable typed errors.
Parameters
| Name | Type | Description |
|---|---|---|
| operation | Async<'value> |
Returns
Flow<'env, exn, 'value>
Creates a flow from a cancellable task factory.
Parameters
| Name | Type | Description |
|---|---|---|
| factory | CancellationToken -> Task<'value> | Starts the operation, observing the supplied cancellation token. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.fromTask (fun token -> client.GetStringAsync(url, token))Creates a flow from a cold task factory whose
Error enters the typed error channel.Parameters
| Name | Type | Description |
|---|---|---|
| factory | CancellationToken -> Task<Result<'value, 'error>> |
Returns
Flow<'env, 'error, 'value>
Creates a flow from a cancellable task factory and treats thrown exceptions as recoverable typed errors.
Parameters
| Name | Type | Description |
|---|---|---|
| factory | CancellationToken -> Task<'value> | Starts the operation, observing the supplied cancellation token. |
Returns
Flow<'env, exn, 'value>
Creates a flow from a cancellable value-task factory.
Parameters
| Name | Type | Description |
|---|---|---|
| factory | CancellationToken -> ValueTask<'value> | Starts the operation, observing the supplied cancellation token. |
Returns
Flow<'env, 'error, 'value>
Creates a flow from a cold value-task factory whose
Error enters the typed error channel.Parameters
| Name | Type | Description |
|---|---|---|
| factory | CancellationToken -> ValueTask<Result<'value, 'error>> |
Returns
Flow<'env, 'error, 'value>
Creates a flow from a cancellable value-task factory and treats thrown exceptions as recoverable typed errors.
Parameters
| Name | Type | Description |
|---|---|---|
| factory | CancellationToken -> ValueTask<'value> | Starts the operation, observing the supplied cancellation token. |
Returns
Flow<'env, exn, 'value>
Observes a task that has already been started.
Parameters
| Name | Type | Description |
|---|---|---|
| startedTask | Task<'value> | A task that is already running. |
Returns
Flow<'env, 'error, 'value>
Observes an already-started task whose
Error enters the typed error channel.Parameters
| Name | Type | Description |
|---|---|---|
| startedTask | Task<Result<'value, 'error>> |
Returns
Flow<'env, 'error, 'value>
Observes a task that has already been started and treats thrown exceptions as recoverable typed errors.
Parameters
| Name | Type | Description |
|---|---|---|
| startedTask | Task<'value> | A task that is already running. |
Returns
Flow<'env, exn, 'value>
Observes a value task that has already been started.
Parameters
| Name | Type | Description |
|---|---|---|
| startedValueTask | ValueTask<'value> | A value task that is already running. |
Returns
Flow<'env, 'error, 'value>
Observes an already-started value task whose
Error enters the typed error channel.Parameters
| Name | Type | Description |
|---|---|---|
| startedValueTask | ValueTask<Result<'value, 'error>> |
Returns
Flow<'env, 'error, 'value>
Observes a value task that has already been started and treats thrown exceptions as recoverable typed errors.
Parameters
| Name | Type | Description |
|---|---|---|
| startedValueTask | ValueTask<'value> | A value task that is already running. |
Returns
Flow<'env, exn, 'value>
Creates a successful synchronous flow.
Parameters
| Name | Type | Description |
|---|---|---|
| value | 'value | The value to wrap in a successful flow. |
Returns
Flow<'env, 'error, 'value>
Alias for
ok that reads well in some call sites.Parameters
| Name | Type | Description |
|---|---|---|
| value | 'value | The value to wrap in a successful flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let result = Flow.succeed 42 |> Flow.run ()
// result = Success 42Alias for
ok that reads well in some call sites.Parameters
| Name | Type | Description |
|---|---|---|
| item | 'value | The value to wrap in a successful flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
Flow.value "constant" |> Flow.run ()Creates a failing synchronous flow.
Parameters
| Name | Type | Description |
|---|---|---|
| failure | 'error | The error value to wrap in a failing flow. |
Returns
Flow<'env, 'error, 'value>
Alias for
error that reads well in some call sites.Parameters
| Name | Type | Description |
|---|---|---|
| failure | 'error | The error value to wrap in a failing flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let result = Flow.fail "error" |> Flow.run ()
// result = Failure (Cause.Fail "error")Creates a defective flow that fails with an exception.
Parameters
| Name | Type | Description |
|---|---|---|
| exn | exn | The exception representing the defect. |
Returns
Flow<'env, 'error, 'value>
Lifts a Result`2 into a synchronous flow.
Parameters
| Name | Type | Description |
|---|---|---|
| result | Result<'value, 'error> | The result value to lift. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
Flow.fromResult (Ok "success") |> Flow.run ()Creates a flow that verifies an input with an environment-aware policy.
Parameters
| Name | Type | Description |
|---|---|---|
| policy | Policy<'env, 'error, 'input, 'output> | The reusable verification rule to apply. |
| input | 'input | The input value to verify. |
Returns
Flow<'env, 'error, 'output>
Installs runtime fiber-lifecycle hooks for diagnostics and telemetry.
Parameters
| Name | Type | Description |
|---|---|---|
| observer | FiberObserver | The lifecycle hooks. Start from FiberObserver.none and override what you need. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Adds runtime fiber-lifecycle hooks, composing with any observer already installed.
Parameters
| Name | Type | Description |
|---|---|---|
| observer | FiberObserver | The lifecycle hooks to add. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Tracks every fiber forked inside the flow in
registry.Parameters
| Name | Type | Description |
|---|---|---|
| registry | FiberRegistry | The registry that receives fiber lifecycle events. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Installs a runtime annotation sink for integration packages.
Parameters
| Name | Type | Description |
|---|---|---|
| sink | string -> string -> unit | |
| flow | Flow<'env, 'error, 'value> |
Returns
Flow<'env, 'error, 'value>
Adds a runtime annotation sink, composing with any sink already installed.
Parameters
| Name | Type | Description |
|---|---|---|
| sink | string -> string -> unit | |
| flow | Flow<'env, 'error, 'value> |
Returns
Flow<'env, 'error, 'value>
Adds a runtime annotation for the duration of the supplied flow.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The annotation key. |
| value | string | The annotation value. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Adds the standard
trace_id runtime annotation for the duration of the supplied flow.Parameters
| Name | Type | Description |
|---|---|---|
| traceId | string | The trace identifier. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Starts a flow in a new fiber without waiting for it to complete.
Parameters
| Name | Type | Description |
|---|---|---|
| flow | Flow<'env, 'error, 'value> | The flow to fork. |
Returns
Flow<'env, 'none, Fiber<'error, 'value>>
Starts a flow in a new fiber carrying a diagnostic name.
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | The diagnostic name recorded in the fiber's metadata. |
| flow | Flow<'env, 'error, 'value> | The flow to fork. |
Returns
Flow<'env, 'none, Fiber<'error, 'value>>
Starts a flow in a new fiber that is deliberately never awaited.
Parameters
| Name | Type | Description |
|---|---|---|
| flow | Flow<'env, 'error, 'value> | The flow to fork. |
Returns
Flow<'env, 'none, Fiber<'error, 'value>>
Waits for a fiber to complete and returns its successful value or typed failure.
Parameters
| Name | Type | Description |
|---|---|---|
| fiber | Fiber<'error, 'value> | The fiber to join. |
Returns
Flow<'env, 'error, 'value>
Signals a fiber to stop and waits for it to finish its cleanup.
Parameters
| Name | Type | Description |
|---|---|---|
| fiber | Fiber<'error, 'value> | The fiber to interrupt. |
Returns
Flow<'env, 'none, Exit<'value, 'error>>
Combines two flows into a tuple of their values, running them concurrently.
Parameters
| Name | Type | Description |
|---|---|---|
| left | Flow<'env, 'error, 'left> | The first flow to combine. |
| right | Flow<'env, 'error, 'right> | The second flow to combine. |
Returns
Flow<'env, 'error, ('left * 'right)>
Verification Examples
let combined = Flow.zipPar (Flow.succeed 1) (Flow.succeed 2)
combined |> Flow.run ()Runs two flows concurrently and returns the result of the first one to complete.
Parameters
| Name | Type | Description |
|---|---|---|
| left | Flow<'env, 'error, 'value> | The first flow to run. |
| right | Flow<'env, 'error, 'value> | The second flow to run. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let fastOrSlow = Flow.race (Flow.succeed "cached") (Flow.succeed "loaded")
fastOrSlow |> Flow.run ()Lifts an option into a synchronous flow with the supplied error.
Parameters
| Name | Type | Description |
|---|---|---|
| error | 'error | The error to return if the option is None. |
| value | 'value option | The option to lift. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let opt = Some "value"
Flow.fromOption "missing" opt |> Flow.run ()Lifts a value option into a synchronous flow with the supplied error.
Parameters
| Name | Type | Description |
|---|---|---|
| error | 'error | The error to return if the value option is ValueNone. |
| value | 'value voption | The value option to lift. |
Returns
Flow<'env, 'error, 'value>
Attaches an environment-derived error to a result that failed without one.
Parameters
| Name | Type | Description |
|---|---|---|
| errorFlow | Flow<'env, 'error, 'error> | A flow that reads the environment to produce an error value. |
| result | Result<'value, unit> | The pure result to bridge. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let result = Result.Error ()
let flow = Flow.orElseFlow (Flow.envWith (fun env -> "error")) resultReads the current environment as the successful flow value.
Returns
Flow<'env, 'error, 'env>
Verification Examples
let myFlow = Flow.env |> Flow.map (fun env -> env)Projects one value from the current environment.
Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'env -> 'value | A function that extracts a value from the environment. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let currentTime () =
Flow.envWith (fun (environment: BaseRuntime) -> environment.Clock.UtcNow())Transforms the successful value of a flow.
Parameters
| Name | Type | Description |
|---|---|---|
| mapper | 'value -> 'next | A function of type 'value -> 'next to transform the successful value. |
| flow | Flow<'env, 'error, 'value> | The source flow of type Axial`3 to transform. |
Returns
Flow<'env, 'error, 'next>
Verification Examples
let flow = Flow.succeed 1 |> Flow.map (fun x -> x + 1)Maps the successful value of a synchronous flow to
unit.Parameters
| Name | Type | Description |
|---|---|---|
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, unit>
Verification Examples
let flow = Flow.succeed 42 |> Flow.ignoreSequences a dependent flow after a successful value.
Parameters
| Name | Type | Description |
|---|---|---|
| binder | 'value -> Flow<'env, 'error, 'next> | A function that takes the successful value and returns a new flow. |
| flow | Flow<'env, 'error, 'value> | The source flow to sequence. |
Returns
Flow<'env, 'error, 'next>
Verification Examples
let flow = Flow.succeed 1 |> Flow.bind (fun x -> Flow.succeed (x + 1))Sequences a synchronous continuation after a successful value.
Parameters
| Name | Type | Description |
|---|---|---|
| flow | Flow<'env, 'error, 'value> | |
| binder | 'value -> Flow<'env, 'error, 'next> |
Returns
Flow<'env, 'error, 'next>
Runs an effect on success and preserves the original value.
Parameters
| Name | Type | Description |
|---|---|---|
| binder | 'value -> Flow<'env, 'error, unit> | A function that produces a side-effect flow from the successful value. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.succeed 42 |> Flow.tap (fun x -> Flow.succeed ())Runs a synchronous side effect on failure and preserves the original error.
Parameters
| Name | Type | Description |
|---|---|---|
| binder | 'error -> Flow<'env, 'error, unit> | A function that produces a side-effect flow from the error value. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.fail "error" |> Flow.tapError (fun err -> Flow.succeed ())Maps the error value of a synchronous flow.
Parameters
| Name | Type | Description |
|---|---|---|
| mapper | 'error -> 'nextError | The function to transform the error value. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'nextError, 'value>
Verification Examples
let flow = Flow.fail "error" |> Flow.mapError (fun err -> err + "!")Attaches diagnostic trace text to any failure cause of the flow.
Parameters
| Name | Type | Description |
|---|---|---|
| trace | string | The diagnostic trace text, typically an operation or boundary name. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = loadUser |> Flow.tracedError "billing.load-user"Maps both the successful value and the failure cause of a synchronous flow.
Parameters
| Name | Type | Description |
|---|---|---|
| onSuccess | 'value -> 'next | The function to transform the success value. |
| onFailure | Cause<'error> -> Cause<'nextError> | The function to transform the failure cause. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'nextError, 'next>
Folds both the successful value and the failure cause into a new flow.
Parameters
| Name | Type | Description |
|---|---|---|
| onSuccess | 'value -> Flow<'env, 'nextError, 'next> | A function that returns a new flow from the success value. |
| onFailure | Cause<'error> -> Flow<'env, 'nextError, 'next> | A function that returns a new flow from the failure cause. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'nextError, 'next>
Catches exceptions raised during execution and simple defect outcomes, then maps them to a typed error.
Parameters
| Name | Type | Description |
|---|---|---|
| handler | exn -> 'error | A function of type exn -> 'error to map the exception. |
| flow | Flow<'env, 'error, 'value> | The source flow of type Axial`3 to monitor. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.die (System.Exception("boom")) |> Flow.catch (fun ex -> "caught: " + ex.Message)Computes a fallback flow from the typed error when the source flow fails.
Parameters
| Name | Type | Description |
|---|---|---|
| fallback | 'error -> Flow<'env, 'error, 'value> | A function that produces a new flow from the error value. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.fail "error" |> Flow.orElseWith (fun err -> Flow.succeed "recovered")Falls back to another flow when the source flow fails.
Parameters
| Name | Type | Description |
|---|---|---|
| fallback | Flow<'env, 'error, 'value> | The flow to run if the source flow fails. |
| flow | Flow<'env, 'error, 'value> | The source flow. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.fail "error" |> Flow.orElse (Flow.succeed "recovered")Runs two flows sequentially and combines their successful values into a tuple.
Parameters
| Name | Type | Description |
|---|---|---|
| left | Flow<'env, 'error, 'left> | The first flow to run. |
| right | Flow<'env, 'error, 'right> | The second flow to run. |
Returns
Flow<'env, 'error, ('left * 'right)>
Verification Examples
Flow.zip (Flow.succeed 1) (Flow.succeed 2) |> Flow.run ()Combines two flows with a mapping function.
Parameters
| Name | Type | Description |
|---|---|---|
| mapper | 'left -> 'right -> 'value | A function that combines the successful values of both flows. |
| left | Flow<'env, 'error, 'left> | The first flow to run. |
| right | Flow<'env, 'error, 'right> | The second flow to run. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.map2 (fun x y -> x + y) (Flow.succeed 1) (Flow.succeed 2)Applies a flow-wrapped function to a flow-wrapped value.
Parameters
| Name | Type | Description |
|---|---|---|
| flow | Flow<'env, 'error, ('value -> 'next)> | A flow that contains a function to apply. |
| value | Flow<'env, 'error, 'value> | A flow that contains the value to apply the function to. |
Returns
Flow<'env, 'error, 'next>
Verification Examples
let flow = Flow.apply (Flow.succeed (fun x -> x + 1)) (Flow.succeed 1)Combines three flows with a mapping function.
Parameters
| Name | Type | Description |
|---|---|---|
| mapper | 'left -> 'middle -> 'right -> 'value | A function that combines the successful values of all three flows. |
| left | Flow<'env, 'error, 'left> | The first flow to run. |
| middle | Flow<'env, 'error, 'middle> | The second flow to run. |
| right | Flow<'env, 'error, 'right> | The third flow to run. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.map3 (fun x y z -> x + y + z) (Flow.succeed 1) (Flow.succeed 2) (Flow.succeed 3)Maps the successful value of a synchronous flow.
Parameters
| Name | Type | Description |
|---|---|---|
| mapper | 'value -> 'next | |
| flow | Flow<'env, 'error, 'value> |
Returns
Flow<'env, 'error, 'next>
Applies a flow-wrapped function to a flow-wrapped value.
Parameters
| Name | Type | Description |
|---|---|---|
| flow | Flow<'env, 'error, ('value -> 'next)> | |
| value | Flow<'env, 'error, 'value> |
Returns
Flow<'env, 'error, 'next>
Runs a flow against an environment derived from the outer environment.
Parameters
| Name | Type | Description |
|---|---|---|
| mapping | 'outerEnvironment -> 'innerEnvironment | A function that maps the outer environment to the inner environment. |
| flow | Flow<'innerEnvironment, 'error, 'value> | The flow to run with the inner environment. |
Returns
Flow<'outerEnvironment, 'error, 'value>
Verification Examples
let flow = Flow.succeed 1 |> Flow.localEnv (fun outer -> outer)Defers flow construction until execution time.
Parameters
| Name | Type | Description |
|---|---|---|
| factory | unit -> Flow<'env, 'error, 'value> | A function that returns the flow to execute. |
Returns
Flow<'env, 'error, 'value>
Verification Examples
let flow = Flow.delay (fun () -> Flow.succeed 42)Transforms a sequence of values into a flow and stops at the first failure.
Parameters
| Name | Type | Description |
|---|---|---|
| mapping | 'value -> Flow<'env, 'error, 'next> | A function that maps each value to a flow. |
| values | 'value seq | The sequence of values to transform. |
Returns
Flow<'env, 'error, 'next list>
Verification Examples
let flows = [1; 2; 3] |> Flow.traverse (fun x -> Flow.succeed (x * 2))Transforms a sequence of flows into a flow of a sequence and stops at the first failure.
Parameters
| Name | Type | Description |
|---|---|---|
| flows | Flow<'env, 'error, 'value> seq | The sequence of flows to run. |
Returns
Flow<'env, 'error, 'value list>
Verification Examples
Flow.sequence [Flow.succeed 1; Flow.succeed 2] |> Flow.run ()Builds a cold async that runs the workflow when it is started.
Parameters
| Name | Type | Description |
|---|---|---|
| environment | 'env | The environment used by the workflow. |
| flow | Flow<'env, 'error, 'value> | The workflow to describe. |
Returns
Async<Exit<'value, 'error>>
Verification Examples
let handle = workflow |> Flow.toAsync environmentStarts the workflow immediately and returns a task handle for its final exit.
Parameters
| Name | Type | Description |
|---|---|---|
| environment | 'env | The environment used by the workflow. |
| flow | Flow<'env, 'error, 'value> | The workflow to start. |
Returns
Task<Exit<'value, 'error>>
Verification Examples
let running = workflow |> Flow.startTask environmentRuns the workflow and blocks until the final exit is available.
Parameters
| Name | Type | Description |
|---|---|---|
| environment | 'env | The environment used by the workflow. |
| flow | Flow<'env, 'error, 'value> | The workflow to run. |
Returns
Exit<'value, 'error>
Verification Examples
let exit = workflow |> Flow.run environment
