FSharp.Core


Array.Parallel Module

Provides parallel operations on arrays

Functions and values

Function or value Description

Array.Parallel.choose chooser array

Full Usage: Array.Parallel.choose chooser array

Parameters:
    chooser : 'T -> 'U option - The function to generate options from the elements.
    array : 'T[] - The input array.

Returns: 'U[] The array of results.

Apply the given function to each element of the array. Return the array comprised of the results x for each element where the function returns Some(x).

Performs the operation in parallel using Parallel.For. The order in which the given function is applied to elements of the input array is not specified.

chooser : 'T -> 'U option

The function to generate options from the elements.

array : 'T[]

The input array.

Returns: 'U[]

The array of results.

ArgumentNullException Thrown when the input array is null.
Example

 let input = [| Some 1; None; Some 2 |]

 input |> Array.Parallel.choose id
Evaluates to [| 1; 2 |]

Example

 let input = [| 1; 2; 3 |]

 input |> Array.Parallel.choose (fun n -> if n % 2 = 0 then Some n else None)
Evaluates to [| 2 |]

Array.Parallel.collect mapping array

Full Usage: Array.Parallel.collect mapping array

Parameters:
    mapping : 'T -> 'U[] -
    array : 'T[] - The input array.

Returns: 'U[] 'U[]

For each element of the array, apply the given function. Concatenate all the results and return the combined array.

Performs the operation in parallel using Parallel.For. The order in which the given function is applied to elements of the input array is not specified.

mapping : 'T -> 'U[]

array : 'T[]

The input array.

Returns: 'U[]

'U[]

ArgumentNullException Thrown when the input array is null.
Example

 type Foo = { Bar: int[] }

 let input = [| {Bar = [| 1; 2 |]}; {Bar = [| 3; 4 |]} |]

 input |> Array.Parallel.collect (fun foo -> foo.Bar)
Evaluates to [| 1; 2; 3; 4 |]

Example

 let input = [| [| 1; 2 |]; [| 3; 4 |] |]

 input |> Array.Parallel.collect id
Evaluates to [| 1; 2; 3; 4 |]

Array.Parallel.init count initializer

Full Usage: Array.Parallel.init count initializer

Parameters:
    count : int -
    initializer : int -> 'T -

Returns: 'T[] The array of results.

Create an array given the dimension and a generator function to compute the elements.

Performs the operation in parallel using Parallel.For. The order in which the given function is applied to indices is not specified.

count : int

initializer : int -> 'T

Returns: 'T[]

The array of results.

Example

 Array.Parallel.init 4 (fun v -> v + 5)
Evaluates to [| 5; 6; 7; 8 |]

Array.Parallel.iter action array

Full Usage: Array.Parallel.iter action array

Parameters:
    action : 'T -> unit -
    array : 'T[] - The input array.

Apply the given function to each element of the array.

Performs the operation in parallel using Parallel.For. The order in which the given function is applied to elements of the input array is not specified.

action : 'T -> unit

array : 'T[]

The input array.

ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| "a"; "b"; "c" |]

 inputs |> Array.Parallel.iter (printfn "%s")
Evaluates to unit and prints the following to the console in an unspecified order:
 a
 c
 b

Array.Parallel.iteri action array

Full Usage: Array.Parallel.iteri action array

Parameters:
    action : int -> 'T -> unit -
    array : 'T[] - The input array.

Apply the given function to each element of the array. The integer passed to the function indicates the index of element.

Performs the operation in parallel using Parallel.For. The order in which the given function is applied to elements of the input array is not specified.

action : int -> 'T -> unit

array : 'T[]

The input array.

ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| "a"; "b"; "c" |]

 inputs |> Array.Parallel.iteri (fun i v -> printfn "{i}: {v}")
Evaluates to unit and prints the following to the console in an unspecified order:
 0: a
 2: c
 1: b

Array.Parallel.map mapping array

Full Usage: Array.Parallel.map mapping array

Parameters:
    mapping : 'T -> 'U -
    array : 'T[] - The input array.

Returns: 'U[] The array of results.

Build a new array whose elements are the results of applying the given function to each of the elements of the array.

Performs the operation in parallel using Parallel.For. The order in which the given function is applied to elements of the input array is not specified.

mapping : 'T -> 'U

array : 'T[]

The input array.

Returns: 'U[]

The array of results.

ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| "a"; "bbb"; "cc" |]

 inputs |> Array.Parallel.map (fun x -> x.Length)
Evaluates to [| 1; 3; 2 |]

Array.Parallel.mapi mapping array

Full Usage: Array.Parallel.mapi mapping array

Parameters:
    mapping : int -> 'T -> 'U -
    array : 'T[] - The input array.

Returns: 'U[] The array of results.

Build a new array whose elements are the results of applying the given function to each of the elements of the array. The integer index passed to the function indicates the index of element being transformed.

Performs the operation in parallel using Parallel.For. The order in which the given function is applied to elements of the input array is not specified.

mapping : int -> 'T -> 'U

array : 'T[]

The input array.

Returns: 'U[]

The array of results.

ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| 10; 10; 10 |]

 inputs |> Array.Parallel.mapi (fun i x -> i + x)
Evaluates to [| 10; 11; 12 |]

Array.Parallel.partition predicate array

Full Usage: Array.Parallel.partition predicate array

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    array : 'T[] - The input array.

Returns: 'T[] * 'T[] The two arrays of results.

Split the collection into two collections, containing the elements for which the given predicate returns "true" and "false" respectively

Performs the operation in parallel using Parallel.For. The order in which the given function is applied to indices is not specified.

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: 'T[] * 'T[]

The two arrays of results.

ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| 1; 2; 3; 4 |]

 inputs |> Array.Parallel.partition (fun x -> x % 2 = 0)
Evaluates to ([|2; 4|], [|1; 3|]).