A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-arraymodule-parallel.html below:

Parallel (FSharp.Core) | FSharp.Core

Returns the average of the elements in the array.

array : ^T array

The input array.

Returns: ^T

The average of the elements in the array.

 [| 1.0; 2.0; 6.0 |] |> Array.Parallel.average

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val average: array: 'T array -> 'T (requires member (+) and member DivideByInt)

Evaluates to 3.0
 [| |] |> Array.Parallel.average

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val average: array: 'T array -> 'T (requires member (+) and member DivideByInt)

Throws ArgumentException

Returns the average of the elements generated by applying the function to each element of the array.

projection : 'T -> ^U

The function to transform the array elements before averaging.

array : 'T array

The input array.

Returns: ^U

The computed average.

 type Foo = { Bar: float }

 let input = [| {Bar = 2.0}; {Bar = 4.0} |]

 input |> Array.Parallel.averageBy (fun foo -> foo.Bar)

type Foo = { Bar: float }

Multiple items

val float: value: 'T -> float (requires member op_Explicit)

--------------------

type float = System.Double

--------------------

type float<'Measure> = float

val input: Foo array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val averageBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member DivideByInt)

val foo: Foo

Foo.Bar: float

Evaluates to 3.0
 type Foo = { Bar: float }

 let input : Foo array = [| |]

 input |> Array.Parallel.averageBy (fun foo -> foo.Bar)

type Foo = { Bar: float }

Multiple items

val float: value: 'T -> float (requires member op_Explicit)

--------------------

type float = System.Double

--------------------

type float<'Measure> = float

val input: Foo array

type 'T array = 'T array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val averageBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member DivideByInt)

val foo: Foo

Foo.Bar: float

Throws ArgumentException

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

chooser : 'T -> 'U option

The function to generate options from the elements.

array : 'T array

The input array.

Returns: 'U array

The array of results.

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

 input |> Array.Parallel.choose id

val input: int option array

union case Option.Some: Value: 'T -> Option<'T>

union case Option.None: Option<'T>

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val choose: chooser: ('T -> 'U option) -> array: 'T array -> 'U array

val id: x: 'T -> 'T

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

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

val input: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val choose: chooser: ('T -> 'U option) -> array: 'T array -> 'U array

val n: int

union case Option.Some: Value: 'T -> Option<'T>

union case Option.None: Option<'T>

Evaluates to [| 2 |]

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

mapping : 'T -> 'U array
array : 'T array

The input array.

Returns: 'U array

'U array

 type Foo = { Bar: int array }

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

 input |> Array.Parallel.collect (fun foo -> foo.Bar)

type Foo = { Bar: int array }

Multiple items

val int: value: 'T -> int (requires member op_Explicit)

--------------------

type int = int32

--------------------

type int<'Measure> = int

type 'T array = 'T array

val input: Foo array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val collect: mapping: ('T -> 'U array) -> array: 'T array -> 'U array

val foo: Foo

Foo.Bar: int array

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

 input |> Array.Parallel.collect id

val input: int array array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val collect: mapping: ('T -> 'U array) -> array: 'T array -> 'U array

val id: x: 'T -> 'T

Evaluates to [| 1; 2; 3; 4 |]

Tests if any element of the array satisfies the given predicate.

predicate : 'T -> bool

The function to test the input elements.

array : 'T array

The input array.

Returns: bool

True if any result from predicate is true.

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

 input |> Array.Parallel.exists (fun elm -> elm % 4 = 0)

val input: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val exists: predicate: ('T -> bool) -> array: 'T array -> bool

val elm: int

Evaluates to true
 let input = [| 1; 2; 3; 4; 5 |]

 input |> Array.Parallel.exists (fun elm -> elm % 6 = 0)

val input: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val exists: predicate: ('T -> bool) -> array: 'T array -> bool

val elm: int

Evaluates to false

Returns a new collection containing only the elements of the collection for which the given predicate returns true.

predicate : 'T -> bool

The function to test the input elements.

array : 'T array

The input array.

Returns: 'T array

An array containing the elements for which the given predicate returns true.

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

 inputs |> Array.Parallel.filter (fun elm -> elm % 2 = 0)

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val filter: predicate: ('T -> bool) -> array: 'T array -> 'T array

val elm: int

Evaluates to [| 2; 4 |]

Tests if all elements of the array satisfy the given predicate.

predicate : 'T -> bool

The function to test the input elements.

array : 'T array

The input array.

Returns: bool

True if all of the array elements satisfy the predicate.

 let isEven a = a % 2 = 0

 [2; 42] |> Array.Parallel.forall isEven // evaluates to true

 [1; 2] |> Array.Parallel.forall isEven // evaluates to false

val isEven: a: int -> bool

val a: int

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val forall: predicate: ('T -> bool) -> array: 'T array -> bool

Applies a key-generating function to each element of an array in parallel and yields an array of unique keys. Each unique key contains an array of all elements that match to this key.

projection : 'T -> 'Key

A function that transforms an element of the array into a comparable key.

array : 'T array

The input array.

Returns: ('Key * 'T array) array

The result array.

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

 inputs |> Array.Parallel.groupBy (fun n -> n % 2)

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val groupBy: projection: ('T -> 'Key) -> array: 'T array -> ('Key * 'T array) array (requires equality)

val n: int

Evaluates to [| (1, [| 1; 3; 5 |]); (0, [| 2; 4 |]) |]

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

count : int
initializer : int -> 'T
Returns: 'T array

The array of results.

 Array.Parallel.init 4 (fun v -> v + 5)

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val init: count: int -> initializer: (int -> 'T) -> 'T array

val v: int

Evaluates to [| 5; 6; 7; 8 |]

Apply the given function to each element of the array.

action : 'T -> unit
array : 'T array

The input array.

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

 inputs |> Array.Parallel.iter (printfn "%s")

val inputs: string array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val iter: action: ('T -> unit) -> array: 'T array -> unit

val printfn: format: Printf.TextWriterFormat<'T> -> 'T

Evaluates to unit and prints the following to the console in an unspecified order:
 a
 c
 b

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

action : int -> 'T -> unit
array : 'T array

The input array.

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

 inputs |> Array.Parallel.iteri (fun i v -> printfn "{i}: {v}")

val inputs: string array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val iteri: action: (int -> 'T -> unit) -> array: 'T array -> unit

val i: int

val v: string

val printfn: format: Printf.TextWriterFormat<'T> -> 'T

Evaluates to unit and prints the following to the console in an unspecified order:
 0: a
 2: c
 1: b

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

mapping : 'T -> 'U
array : 'T array

The input array.

Returns: 'U array

The array of results.

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

 inputs |> Array.Parallel.map (fun x -> x.Length)

val inputs: string array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array

val x: string

property System.String.Length: int with get

Evaluates to [| 1; 3; 2 |]

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.

mapping : int -> 'T -> 'U
array : 'T array

The input array.

Returns: 'U array

The array of results.

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

 inputs |> Array.Parallel.mapi (fun i x -> i + x)

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val mapi: mapping: (int -> 'T -> 'U) -> array: 'T array -> 'U array

val i: int

val x: int

Evaluates to [| 10; 11; 12 |]

Returns the greatest of all elements of the array, compared via Operators.max.

array : 'T array

The input array.

Returns: 'T

The maximum element.

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

 inputs |> Array.Parallel.max

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val max: array: 'T array -> 'T (requires comparison)

Evaluates to 12
 let inputs: int array= [| |]

 inputs |> Array.Parallel.max

val inputs: int array

Multiple items

val int: value: 'T -> int (requires member op_Explicit)

--------------------

type int = int32

--------------------

type int<'Measure> = int

type 'T array = 'T array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val max: array: 'T array -> 'T (requires comparison)

Throws System.ArgumentException.

Returns the greatest of all elements of the array, compared via Operators.max on the function result.

projection : 'T -> 'U

The function to transform the elements into a type supporting comparison.

array : 'T array

The input array.

Returns: 'T

The maximum element.

 let inputs = [| "aaa"; "b"; "cccc" |]

 inputs |> Array.Parallel.maxBy (fun s -> s.Length)

val inputs: string array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val maxBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)

val s: string

property System.String.Length: int with get

Evaluates to "cccc"
 let inputs: string array= [| |]

 inputs |> Array.Parallel.maxBy (fun s -> s.Length)

val inputs: string array

Multiple items

val string: value: 'T -> string

--------------------

type string = System.String

type 'T array = 'T array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val maxBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)

val s: string

property System.String.Length: int with get

Throws System.ArgumentException.

Returns the smallest of all elements of the array, compared via Operators.min.

array : 'T array

The input array.

Returns: 'T

The minimum element.

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

 inputs |> Array.Parallel.min

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val min: array: 'T array -> 'T (requires comparison)

Evaluates to 10
 let inputs: int array= [| |]

 inputs |> Array.Parallel.min

val inputs: int array

Multiple items

val int: value: 'T -> int (requires member op_Explicit)

--------------------

type int = int32

--------------------

type int<'Measure> = int

type 'T array = 'T array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val min: array: 'T array -> 'T (requires comparison)

Throws System.ArgumentException.

Returns the lowest of all elements of the array, compared via Operators.min on the function result.

projection : 'T -> 'U

The function to transform the elements into a type supporting comparison.

array : 'T array

The input array.

Returns: 'T

The minimum element.

 let inputs = [| "aaa"; "b"; "cccc" |]

 inputs |> Array.Parallel.minBy (fun s -> s.Length)

val inputs: string array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val minBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)

val s: string

property System.String.Length: int with get

Evaluates to "b"
 let inputs: string array= [| |]

 inputs |> Array.Parallel.minBy (fun s -> s.Length)

val inputs: string array

Multiple items

val string: value: 'T -> string

--------------------

type string = System.String

type 'T array = 'T array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val minBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)

val s: string

property System.String.Length: int with get

Throws System.ArgumentException.

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

predicate : 'T -> bool

The function to test the input elements.

array : 'T array

The input array.

Returns: 'T array * 'T array

The two arrays of results.

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

 inputs |> Array.Parallel.partition (fun x -> x % 2 = 0)

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val partition: predicate: ('T -> bool) -> array: 'T array -> 'T array * 'T array

val x: int

Evaluates to ([|2; 4|], [|1; 3|]).

Applies a function to each element of the array in parallel, threading an accumulator argument through the computation for each thread involved in the computation. After processing entire input, results from all threads are reduced together. Raises ArgumentException if the array is empty.

reduction : 'T -> 'T -> 'T

The function to reduce a pair of elements to a single element.

array : 'T array

The input array.

Returns: 'T

Result of the reductions.

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

 inputs |> Array.Parallel.reduce (fun a b -> a + b)

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val reduce: reduction: ('T -> 'T -> 'T) -> array: 'T array -> 'T

val a: int

val b: int

Evaluates to 1 + 3 + 4 + 2. However, the system could have decided to compute (1+3) and (4+2) first, and then put them together.

Applies a projection function to each element of the array in parallel, reducing elements in each thread with a dedicated 'reduction' function. After processing entire input, results from all threads are reduced together. Raises ArgumentException if the array is empty.

projection : 'T -> 'U

The function to project from elements of the input array

reduction : 'U -> 'U -> 'U

The function to reduce a pair of projected elements to a single element.

array : 'T array

The input array.

Returns: 'U

The final result of the reductions.

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

 inputs |> Array.Parallel.reduceBy  (fun x -> int x) (+)

val inputs: string array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val reduceBy: projection: ('T -> 'U) -> reduction: ('U -> 'U -> 'U) -> array: 'T array -> 'U

val x: string

Multiple items

val int: value: 'T -> int (requires member op_Explicit)

--------------------

type int = int32

--------------------

type int<'Measure> = int

Evaluates to 1 + 3 + 4 + 2. However, the system could have decided to compute (1+3) and (4+2) first, and then put them together.

Sorts the elements of an array in parallel, returning a new array. Elements are compared using Operators.compare.

array : 'T array

The input array.

Returns: 'T array

The sorted array.

 let input = [| 8; 4; 3; 1; 6; 1 |]

 Array.Parallel.sort input

val input: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val sort: array: 'T array -> 'T array (requires comparison)

Evaluates to [| 1; 1 3; 4; 6; 8 |].

Sorts the elements of an array in parallel, using the given projection for the keys and returning a new array. Elements are compared using Operators.compare.

projection : 'T -> 'Key

The function to transform array elements into the type that is compared.

array : 'T array

The input array.

Returns: 'T array

The sorted array.

 let input = [| "a"; "bbb"; "cccc"; "dd" |]

 input |> Array.Parallel.sortBy (fun s -> s.Length)

val input: string array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val sortBy: projection: ('T -> 'Key) -> array: 'T array -> 'T array (requires comparison)

val s: string

property System.String.Length: int with get

Evaluates to [|"a"; "dd"; "bbb"; "cccc"|].

Sorts the elements of an array in parallel, in descending order, using the given projection for the keys and returning a new array. Elements are compared using Operators.compare.

projection : 'T -> 'Key

The function to transform array elements into the type that is compared.

array : 'T array

The input array.

Returns: 'T array

The sorted array.

 let input = [| "a"; "bbb"; "cccc"; "dd" |]

 input |> Array.Parallel.sortByDescending (fun s -> s.Length)

val input: string array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val sortByDescending: projection: ('T -> 'Key) -> array: 'T array -> 'T array (requires comparison)

val s: string

property System.String.Length: int with get

Evaluates to [|"cccc"; "bbb"; "dd"; "a"|].

Sorts the elements of an array in parallel, in descending order, returning a new array. Elements are compared using Operators.compare.

array : 'T array

The input array.

Returns: 'T array

The sorted array.

 let input = [| 8; 4; 3; 1; 6; 1 |]

 input |> Array.Parallel.sortDescending

val input: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val sortDescending: array: 'T array -> 'T array (requires comparison)

Evaluates to [| 8; 6; 4; 3; 1; 1 |].

Sorts the elements of an array by mutating the array in-place in parallel, using the given comparison function. Elements are compared using Operators.compare.

array : 'T array

The input array.

 let array = [| 8; 4; 3; 1; 6; 1 |]

 Array.sortInPlace array

Multiple items

val array: int array

--------------------

type 'T array = 'T array

module Array from Microsoft.FSharp.Collections

val sortInPlace: array: 'T array -> unit (requires comparison)

After evaluation array contains [| 1; 1; 3; 4; 6; 8 |].

Sorts the elements of an array by mutating the array in-place in parallel, using the given projection for the keys. Elements are compared using Operators.compare.

projection : 'T -> 'Key

The function to transform array elements into the type that is compared.

array : 'T array

The input array.

 let array = [| "a"; "bbb"; "cccc"; "dd" |]

 array |> Array.Parallel.sortInPlaceBy (fun s -> s.Length)

Multiple items

val array: string array

--------------------

type 'T array = 'T array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val sortInPlaceBy: projection: ('T -> 'Key) -> array: 'T array -> unit (requires comparison)

val s: string

property System.String.Length: int with get

After evaluation array contains [|"a"; "dd"; "bbb"; "cccc"|].

Sorts the elements of an array by mutating the array in-place in parallel, using the given comparison function as the order.

comparer : 'T -> 'T -> int

The function to compare pairs of array elements.

array : 'T array

The input array.

The following sorts entries using a comparison function that compares string lengths then index numbers:

 let compareEntries (n1: int, s1: string) (n2: int, s2: string) =
     let c = compare s1.Length s2.Length
     if c <> 0 then c else
     compare n1 n2

 let array = [| (0,"aa"); (1,"bbb"); (2,"cc"); (3,"dd") |]

 array |> Array.Parallel.sortInPlaceWith compareEntries

val compareEntries: n1: int * s1: string -> n2: int * s2: string -> int

val n1: int

Multiple items

val int: value: 'T -> int (requires member op_Explicit)

--------------------

type int = int32

--------------------

type int<'Measure> = int

val s1: string

Multiple items

val string: value: 'T -> string

--------------------

type string = System.String

val n2: int

val s2: string

val c: int

val compare: e1: 'T -> e2: 'T -> int (requires comparison)

property System.String.Length: int with get

Multiple items

val array: (int * string) array

--------------------

type 'T array = 'T array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val sortInPlaceWith: comparer: ('T -> 'T -> int) -> array: 'T array -> unit

After evaluation array contains [|(0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb")|].

Sorts the elements of an array in parallel, using the given comparison function as the order, returning a new array.

comparer : 'T -> 'T -> int

The function to compare pairs of array elements.

array : 'T array

The input array.

Returns: 'T array

The sorted array.

Sort an array of pairs using a comparison function that compares string lengths then index numbers:

 let compareEntries (n1: int, s1: string) (n2: int, s2: string) =
     let c = compare s1.Length s2.Length
     if c <> 0 then c else
     compare n1 n2

 let input = [| (0,"aa"); (1,"bbb"); (2,"cc"); (3,"dd") |]

 input |> Array.Parallel.sortWith compareEntries

val compareEntries: n1: int * s1: string -> n2: int * s2: string -> int

val n1: int

Multiple items

val int: value: 'T -> int (requires member op_Explicit)

--------------------

type int = int32

--------------------

type int<'Measure> = int

val s1: string

Multiple items

val string: value: 'T -> string

--------------------

type string = System.String

val n2: int

val s2: string

val c: int

val compare: e1: 'T -> e2: 'T -> int (requires comparison)

property System.String.Length: int with get

val input: (int * string) array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val sortWith: comparer: ('T -> 'T -> int) -> array: 'T array -> 'T array

Evaluates to [|(0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb")|].

Returns the sum of the elements in the array.

array : ^T array

The input array.

Returns: ^T

The resulting sum.

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

 input |> Array.Parallel.sum

val input: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val sum: array: 'T array -> 'T (requires member (+) and member Zero)

Evaluates to 11.

Returns the sum of the results generated by applying the function to each element of the array.

projection : 'T -> ^U

The function to transform the array elements into the type to be summed.

array : 'T array

The input array.

Returns: ^U

The resulting sum.

 let input = [| "aa"; "bbb"; "cc" |]

 input |> Array.Parallel.sumBy (fun s -> s.Length)

val input: string array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val sumBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member Zero)

val s: string

property System.String.Length: int with get

Evaluates to 7.

Returns the first element for which the given function returns True. Returns None if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

array : 'T array

The input array.

Returns: 'T option

The first element that satisfies the predicate, or None.

Try to find the first even number:

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

 inputs |> Array.Parallel.tryFind (fun elm -> elm % 2 = 0)

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val tryFind: predicate: ('T -> bool) -> array: 'T array -> 'T option

val elm: int

Evaluates to Some 2.

Try to find the first even number:

 let inputs = [| 1; 5; 3 |]

 inputs |> Array.Parallel.tryFind (fun elm -> elm % 2 = 0)

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val tryFind: predicate: ('T -> bool) -> array: 'T array -> 'T option

val elm: int

Evaluates to None

Returns the index of the first element in the array that satisfies the given predicate. Returns None if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

array : 'T array

The input array.

Returns: int option

The index of the first element that satisfies the predicate, or None.

Try to find the index of the first even number:

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

 inputs |> Array.Parallel.tryFindIndex (fun elm -> elm % 2 = 0)

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val tryFindIndex: predicate: ('T -> bool) -> array: 'T array -> int option

val elm: int

Evaluates to Some 1

Try to find the index of the first even number:

 let inputs = [| 1; 3; 5; 7 |]

 inputs |> Array.Parallel.tryFindIndex (fun elm -> elm % 2 = 0)

val inputs: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val tryFindIndex: predicate: ('T -> bool) -> array: 'T array -> int option

val elm: int

Evaluates to None

Applies the given function to successive elements, returning the first result where the function returns Some(x) for some x. If the function never returns Some(x) then None is returned.

chooser : 'T -> 'U option

The function to transform the array elements into options.

array : 'T array

The input array.

Returns: 'U option

The first transformed element that is Some(x).

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

 input |> Array.Parallel.tryPick (fun n -> if n % 2 = 0 then Some (string n) else None)

val input: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val tryPick: chooser: ('T -> 'U option) -> array: 'T array -> 'U option

val n: int

union case Option.Some: Value: 'T -> Option<'T>

Multiple items

val string: value: 'T -> string

--------------------

type string = System.String

union case Option.None: Option<'T>

Evaluates to Some 2.
 let input = [| 1; 2; 3 |]

 input |> Array.Parallel.tryPick (fun n -> if n > 3 = 0 then Some (string n) else None)

val input: int array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val tryPick: chooser: ('T -> 'U option) -> array: 'T array -> 'U option

val n: int

union case Option.Some: Value: 'T -> Option<'T>

Multiple items

val string: value: 'T -> string

--------------------

type string = System.String

union case Option.None: Option<'T>

Evaluates to None.

Combines the two arrays into an array of pairs. The two arrays must have equal lengths, otherwise an ArgumentException is raised.

array1 : 'T1 array

The first input array.

array2 : 'T2 array

The second input array.

Returns: ('T1 * 'T2) array

The array of tupled elements.

 let numbers = [|1; 2|]
 let names = [|"one"; "two"|]

 Array.Parallel.zip numbers names

val numbers: int array

val names: string array

module Array from Microsoft.FSharp.Collections

module Parallel from Microsoft.FSharp.Collections.ArrayModule

val zip: array1: 'T1 array -> array2: 'T2 array -> ('T1 * 'T2) array

Evaluates to [| (1, "one"); (2, "two") |].

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4