FSharpPlus


Extensions Module

Module containing F#+ Extension Methods on existing types

Table of contents

FSharp.Core Extensions

Type extensions

Type extension Description

Async.AsTask(computation, ?cancellationToken)

Full Usage: Async.AsTask(computation, ?cancellationToken)

Parameters:
    computation : Async<'T> - The asynchronous computation to execute.
    ?cancellationToken : CancellationToken - The CancellationToken to associate with the computation. The default is used if this parameter is not provided.

Returns: Task<'T> A Task that will be completed in the corresponding state once the computation terminates (produces the result, throws exception or gets canceled)

Runs an asynchronous computation, starting immediately on the current operating system thread, but also returns the execution as Task This behaves exactly like Async.StartImmediateAsTask but without unexpected exceptions-wrapping.

If no cancellation token is provided then the default cancellation token is used. You may prefer using this method if you want to achive a similar behviour to async await in C# as async computation starts on the current thread with an ability to return a result.

Extended Type: Async

computation : Async<'T>

The asynchronous computation to execute.

?cancellationToken : CancellationToken

The CancellationToken to associate with the computation. The default is used if this parameter is not provided.

Returns: Task<'T>

A Task that will be completed in the corresponding state once the computation terminates (produces the result, throws exception or gets canceled)

Example

 printfn "A"

 let t =
     async {
         printfn "B"
         do! Async.Sleep(1000)
         printfn "C"
     } |> Async.AsTask

 printfn "D"
 t.Wait()
 printfn "E"
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
val t: obj
val async: AsyncBuilder
Multiple items
type Async = static member AsBeginEnd: computation: ('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit) static member AwaitEvent: event: IEvent<'Del,'T> * ?cancelAction: (unit -> unit) -> Async<'T> (requires delegate and 'Del :> Delegate) static member AwaitIAsyncResult: iar: IAsyncResult * ?millisecondsTimeout: int -> Async<bool> static member AwaitTask: task: Task<'T> -> Async<'T> + 1 overload static member AwaitWaitHandle: waitHandle: WaitHandle * ?millisecondsTimeout: int -> Async<bool> static member CancelDefaultToken: unit -> unit static member Catch: computation: Async<'T> -> Async<Choice<'T,exn>> static member Choice: computations: Async<'T option> seq -> Async<'T option> static member FromBeginEnd: beginAction: (AsyncCallback * obj -> IAsyncResult) * endAction: (IAsyncResult -> 'T) * ?cancelAction: (unit -> unit) -> Async<'T> + 3 overloads static member FromContinuations: callback: (('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) -> Async<'T> ...

--------------------
type Async<'T>
static member Async.Sleep: dueTime: System.TimeSpan -> Async<unit>
static member Async.Sleep: millisecondsDueTime: int -> Async<unit>
Prints "A", "B", "D" immediately, then "C", "E" in 1 second.

Other module members

Type extensions

Type extension Description

Async.Await(task)

Full Usage: Async.Await(task)

Parameters:
    task : Task<'T> - The task to await.

Returns: Async<'T>

Return an asynchronous computation that will wait for the given task to complete and return its result.

Prefer this over Async.AwaitTask. If an exception occurs in the asynchronous computation then an exception is re-raised by this function. If the task is cancelled then Tasks.TaskCanceledException is raised. Note that the task may be governed by a different cancellation token to the overall async computation where the Await occurs. In practice you should normally start the task with the cancellation token returned by let! ct = Async.CancellationToken, and catch any Tasks.TaskCanceledException at the point where the overall async is started.

Extended Type: Async

task : Task<'T>

The task to await.

Returns: Async<'T>

Async.Await(task)

Full Usage: Async.Await(task)

Parameters:
    task : Task - The task to await.

Returns: Async<unit>

Return an asynchronous computation that will wait for the given task to complete and return its result.

Prefer this over Async.AwaitTask. If an exception occurs in the asynchronous computation then an exception is re-raised by this function. If the task is cancelled then Tasks.TaskCanceledException is raised. Note that the task may be governed by a different cancellation token to the overall async computation where the Await occurs. In practice you should normally start the task with the cancellation token returned by let! ct = Async.CancellationToken, and catch any Tasks.TaskCanceledException at the point where the overall async is started.

Extended Type: Async

task : Task

The task to await.

Returns: Async<unit>

Async.Bisequential(t)

Full Usage: Async.Bisequential(t)

Parameters:
Returns: Async<Result<'T, 'Error>>

Creates an async Result from a Result where both cases are async.

Extended Type: Async

t : Result<Async<'T>, Async<'Error>>
Returns: Async<Result<'T, 'Error>>

Async.Bisequential(t)

Full Usage: Async.Bisequential(t)

Parameters:
Returns: Async<Choice<'T, 'Choice2Of2>>

Creates an async Choice from a Choice where both cases are async.

Extended Type: Async

t : Choice<Async<'T>, Async<'Choice2Of2>>
Returns: Async<Choice<'T, 'Choice2Of2>>

this.GetSlice

Full Usage: this.GetSlice

Parameters:
    () : unit

Returns: int option * int option -> IEnumerable<'T>

Extended Type: IEnumerable

() : unit
Returns: int option * int option -> IEnumerable<'T>

this.GetSlice

Full Usage: this.GetSlice

Returns: int option * int option -> IEnumerable<'T>
Modifiers: abstract

Extended Type: IEnumerable

Returns: int option * int option -> IEnumerable<'T>

this.GetSlice

Full Usage: this.GetSlice

Parameters:
    () : unit

Returns: int option * int option -> List<'T>

Extended Type: List

() : unit
Returns: int option * int option -> List<'T>

this.GetSlice

Full Usage: this.GetSlice

Returns: int option * int option -> List<'T>

Extended Type: List

Returns: int option * int option -> List<'T>

Choice.Parallel(choice2Combiner, t)

Full Usage: Choice.Parallel(choice2Combiner, t)

Parameters:
    choice2Combiner : 'T2 -> 'T2 -> 'T2
    t : Choice<'T1, 'T2> seq

Returns: Choice<'T1 seq, 'T2>

Returns all Choice2Of2's combined, otherwise a sequence of all Choice1Of2 elements.

Extended Type: Choice

choice2Combiner : 'T2 -> 'T2 -> 'T2
t : Choice<'T1, 'T2> seq
Returns: Choice<'T1 seq, 'T2>

Result.Parallel(errorCombiner, t)

Full Usage: Result.Parallel(errorCombiner, t)

Parameters:
    errorCombiner : 'TError -> 'TError -> 'TError
    t : Result<'T, 'TError> seq

Returns: Result<'T seq, 'TError>

Returns all Errors combined, otherwise a sequence of all elements.

Extended Type: Result

errorCombiner : 'TError -> 'TError -> 'TError
t : Result<'T, 'TError> seq
Returns: Result<'T seq, 'TError>

Task.Sequential(t)

Full Usage: Task.Sequential(t)

Parameters:
Returns: Task<Result<'T, 'Error>>

Creates a task Result from a Result where the Ok case is a task.

Extended Type: Task

t : Result<Task<'T>, 'Error>
Returns: Task<Result<'T, 'Error>>

Task.Sequential(t)

Full Usage: Task.Sequential(t)

Parameters:
Returns: Task<Choice<'T, 'Error>>

Creates a task Result from a Result where the Ok case is a task.

Extended Type: Task

t : Choice<Task<'T>, 'Error>
Returns: Task<Choice<'T, 'Error>>

Async.Sequential(t)

Full Usage: Async.Sequential(t)

Parameters:
Returns: Async<'T list>

Combine all asyncs in one, chaining them in sequence order.

Extended Type: Async

t : Async<'T> list
Returns: Async<'T list>

Async.Sequential(t)

Full Usage: Async.Sequential(t)

Parameters:
Returns: Async<'a array>

Combine all asyncs in one, chaining them in sequence order.

Extended Type: Async

t : Async<'a> array
Returns: Async<'a array>

Async.Sequential(t)

Full Usage: Async.Sequential(t)

Parameters:
Returns: Async<Result<'T, 'Error>>

Creates an async Result from a Result where the Ok case is async.

Extended Type: Async

t : Result<Async<'T>, 'Error>
Returns: Async<Result<'T, 'Error>>

Async.Sequential(t)

Full Usage: Async.Sequential(t)

Parameters:
Returns: Async<Choice<'T, 'Choice2Of2>>

Creates an async Choice from a Choice where the Choice1Of2 case is async.

Extended Type: Async

t : Choice<Async<'T>, 'Choice2Of2>
Returns: Async<Choice<'T, 'Choice2Of2>>

Option.Sequential(t)

Full Usage: Option.Sequential(t)

Parameters:
    t : 'T option seq

Returns: 'T seq option

Returns None if it contains a None element, otherwise a list of all elements.

Extended Type: Option

t : 'T option seq
Returns: 'T seq option

ValueOption.Sequential(t)

Full Usage: ValueOption.Sequential(t)

Parameters:
    t : 'T voption seq

Returns: 'T seq voption

Returns None if it contains a None element, otherwise a list of all elements.

Extended Type: ValueOption

t : 'T voption seq
Returns: 'T seq voption

Choice.Sequential(t)

Full Usage: Choice.Sequential(t)

Parameters:
Returns: Choice<'T1 seq, 'T2>

Returns the first Choice2Of2 if it contains a Choice2Of2 element, otherwise a list of all Choice1Of2 elements.

Extended Type: Choice

t : Choice<'T1, 'T2> seq
Returns: Choice<'T1 seq, 'T2>

Result.Sequential(t)

Full Usage: Result.Sequential(t)

Parameters:
Returns: Result<'T seq, 'TError>

Returns the first Error if it contains an Error element, otherwise a sequence of all elements.

Extended Type: Result

t : Result<'T, 'TError> seq
Returns: Result<'T seq, 'TError>

Result.Sequential(t)

Full Usage: Result.Sequential(t)

Parameters:
    t : Result<'T, 'TError> list

Returns: Result<'T list, 'TError>

Returns the first Error if it contains an Error element, otherwise a list of all elements.

Extended Type: Result

t : Result<'T, 'TError> list
Returns: Result<'T list, 'TError>

Result.Sequential(t)

Full Usage: Result.Sequential(t)

Parameters:
    t : Result<'T, 'TError> option

Returns: Result<'T option, 'TError>

Returns the Error if it contains an Error element, otherwise the option inside an Ok.

Extended Type: Result

t : Result<'T, 'TError> option
Returns: Result<'T option, 'TError>

Result.Sequential(t)

Full Usage: Result.Sequential(t)

Parameters:
    t : Result<'T, 'TError> voption

Returns: Result<'T voption, 'TError>

Returns the Error if it contains an Error element, otherwise the voption inside an Ok.

Extended Type: Result

t : Result<'T, 'TError> voption
Returns: Result<'T voption, 'TError>

Async.SequentialLazy(t)

Full Usage: Async.SequentialLazy(t)

Parameters:
Returns: Async<'T seq>

Combine all asyncs in one, chaining them in sequence order. Similar to Async.Sequential but the returned Async contains a sequence, which is lazily evaluated.

Extended Type: Async

t : Async<'T> seq
Returns: Async<'T seq>

Task.WhenAll(tasks, ?cancellationToken)

Full Usage: Task.WhenAll(tasks, ?cancellationToken)

Parameters:
Returns: Task<'a[]>

Extended Type: Task

tasks : Task<'a>[]
?cancellationToken : CancellationToken
Returns: Task<'a[]>