Effect Type
Creates effects. Effect.Create turns a function of an environment into an effect, and is how effects are
made from the interfaces that describe side effects. The function may return a plain value, a Result, a
Task, a ValueTask or an Async, of a value or of a Result; returning a Result
lets the effect fail.
Example
The usual pattern: an interface describing the side effect, a provider interface exposing it, and a function
creating the effect, which requires any environment that implements the provider (#IConsoleProvider).
type IConsole =
abstract ReadLine: unit -> string
abstract WriteLine: string -> unit
type IConsoleProvider =
abstract Console: IConsole
module Console =
let readLine () =
Effect.Create(fun (p: #IConsoleProvider) -> p.Console.ReadLine())
let writeLine line =
Effect.Create(fun (p: #IConsoleProvider) -> p.Console.WriteLine line)
type IConsole =
abstract ReadLine: unit -> string
abstract WriteLine: string -> unit
type unit = Unit
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
val string: value: 'T -> string
--------------------
type string = System.String
type IConsoleProvider =
abstract Console: IConsole
val readLine: unit -> 'a
val writeLine: line: 'a -> 'b
val line: 'a
The Orsak.Myriad generators can write the functions of such a module from the interface.
Static members
| Static member |
Description
|
|
|
|
|
|
|
Full Usage:
Effect.Error(error)
Parameters:
'e
-
The error the effect will fail with.
Returns: Effect<'a, 'b, 'e>
Type parameters: 'e, 'a, 'b |
Creates a failed effect from the provided error.
|
Orsak