Logo Orsak

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
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

Effect.Create(f)

Full Usage: Effect.Create(f)

Parameters:
    f : 'a -> Async<Result<'b, 'e>> - The effect creation function

Returns: Effect<'a, 'b, 'e>
Type parameters: 'a, 'b, 'e

Creates an effect from a function.

f : 'a -> Async<Result<'b, 'e>>

The effect creation function

Returns: Effect<'a, 'b, 'e>

Effect.Create(f)

Full Usage: Effect.Create(f)

Parameters:
Returns: Effect<'a, 'b, 'e>
Type parameters: 'a, 'b, 'e

Creates an effect from a function.

f : 'a -> ValueTask<Result<'b, 'e>>

The effect creation function

Returns: Effect<'a, 'b, 'e>

Effect.Create(f)

Full Usage: Effect.Create(f)

Parameters:
    f : 'a -> Task<Result<'b, 'e>> - The effect creation function

Returns: Effect<'a, 'b, 'e>
Type parameters: 'a, 'b, 'e

Creates an effect from a function.

f : 'a -> Task<Result<'b, 'e>>

The effect creation function

Returns: Effect<'a, 'b, 'e>

Effect.Error(error)

Full Usage: Effect.Error(error)

Parameters:
    error : '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.

error : 'e

The error the effect will fail with.

Returns: Effect<'a, 'b, 'e>

Type something to start searching.