FSharp.Core


Array Module

Contains operations for working with arrays.

See also F# Language Guide - Arrays.

Nested modules

Modules Description

Parallel

Provides parallel operations on arrays

Functions and values

Function or value Description

Array.allPairs array1 array2

Full Usage: Array.allPairs array1 array2

Parameters:
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.

Returns: ('T1 * 'T2)[] The resulting array of pairs.

Returns a new array that contains all pairings of elements from the first and second arrays.

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

Returns: ('T1 * 'T2)[]

The resulting array of pairs.

ArgumentNullException Thrown when either of the input arrays is null.
Example

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

Array.append array1 array2

Full Usage: Array.append array1 array2

Parameters:
    array1 : 'T[] - The first input array.
    array2 : 'T[] - The second input array.

Returns: 'T[] The resulting array.

Builds a new array that contains the elements of the first array followed by the elements of the second array.

array1 : 'T[]

The first input array.

array2 : 'T[]

The second input array.

Returns: 'T[]

The resulting array.

ArgumentNullException Thrown when either of the input arrays is null.
Example

 Array.append [| 1; 2 |] [| 3; 4 |]
Evaluates to [| 1; 2; 3; 4 |].

Array.average array

Full Usage: Array.average array

Parameters:
    array : ^T[] - The input array.

Returns: ^T The average of the elements in the array.
Modifiers: inline
Type parameters: ^T

Returns the average of the elements in the array.

array : ^T[]

The input array.

Returns: ^T

The average of the elements in the array.

ArgumentException Thrown when array is empty.
ArgumentNullException Thrown when the input array is null.
Example

 [| 1.0; 2.0; 6.0 |] |> Array.average
Evaluates to 3.0

Example

 [| |] |> Array.average
Throws ArgumentException

Array.averageBy projection array

Full Usage: Array.averageBy projection array

Parameters:
    projection : 'T -> ^U - The function to transform the array elements before averaging.
    array : 'T[] - The input array.

Returns: ^U The computed average.
Modifiers: inline
Type parameters: 'T, ^U

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

The input array.

Returns: ^U

The computed average.

ArgumentException Thrown when array is empty.
ArgumentNullException Thrown when the input array is null.
Example

 type Foo = { Bar: float }

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

 input |> Array.averageBy (fun foo -> foo.Bar)
Evaluates to 3.0

Example

 type Foo = { Bar: float }

 let input : Foo[] = [| |]

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

Array.blit source sourceIndex target targetIndex count

Full Usage: Array.blit source sourceIndex target targetIndex count

Parameters:
    source : 'T[] - The source array.
    sourceIndex : int - The starting index of the source array.
    target : 'T[] - The target array.
    targetIndex : int - The starting index of the target array.
    count : int - The number of elements to copy.

Modifiers: inline
Type parameters: 'T

Reads a range of elements from the first array and write them into the second.

Slicing syntax is generally preferred, e.g.

 let source = [| 12; 13; 14 |]
 let target = [| 0; 1; 2; 3; 4; 5 |]
 target[3..4] <- source[1..2]

source : 'T[]

The source array.

sourceIndex : int

The starting index of the source array.

target : 'T[]

The target array.

targetIndex : int

The starting index of the target array.

count : int

The number of elements to copy.

ArgumentNullException Thrown when either of the input arrays is null.
ArgumentException Thrown when any of sourceIndex, targetIndex or count are negative, or when there aren't enough elements in source or target.
Example

 let source = [| 12; 13; 14 |]
 let target = [| 0; 1; 2; 3; 4; 5 |]

 Array.blit source 1 target 3 2
After evaluation target contains [| 0; 1; 2; 12; 13; 5 |].

Array.choose chooser array

Full Usage: Array.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.

Applies the given function to each element of the array. Returns 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[]

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.choose id
Evaluates to [| 1; 2 |]

Example

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

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

Array.chunkBySize chunkSize array

Full Usage: Array.chunkBySize chunkSize array

Parameters:
    chunkSize : int - The maximum size of each chunk.
    array : 'T[] - The input array.

Returns: 'T[][] The array divided into chunks.

Divides the input array into chunks of size at most chunkSize.

chunkSize : int

The maximum size of each chunk.

array : 'T[]

The input array.

Returns: 'T[][]

The array divided into chunks.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when chunkSize is not positive.
Example

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

 input |> Array.chunkBySize 2
Evaluates to [| [|1; 2|]; [|3|] |]

Example

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

 input |> Array.chunkBySize -2
Throws ArgumentException

Array.collect mapping array

Full Usage: Array.collect mapping array

Parameters:
    mapping : 'T -> 'U[] - The function to create sub-arrays from the input array elements.
    array : 'T[] - The input array.

Returns: 'U[] The concatenation of the sub-arrays.

For each element of the array, applies the given function. Concatenates all the results and return the combined array.

mapping : 'T -> 'U[]

The function to create sub-arrays from the input array elements.

array : 'T[]

The input array.

Returns: 'U[]

The concatenation of the sub-arrays.

ArgumentNullException Thrown when the input array is null.
Example

 type Foo = { Bar: int[] }

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

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

Example

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

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

Array.compareWith comparer array1 array2

Full Usage: Array.compareWith comparer array1 array2

Parameters:
    comparer : 'T -> 'T -> int - A function that takes an element from each array and returns an int. If it evaluates to a non-zero value iteration is stopped and that value is returned.
    array1 : 'T[] - The first input array.
    array2 : 'T[] - The second input array.

Returns: int Returns the first non-zero result from the comparison function. If the first array has a larger element, the return value is always positive. If the second array has a larger element, the return value is always negative. When the elements are equal in the two arrays, 1 is returned if the first array is longer, 0 is returned if they are equal in length, and -1 is returned when the second array is longer.
Modifiers: inline
Type parameters: 'T

Compares two arrays using the given comparison function, element by element.

comparer : 'T -> 'T -> int

A function that takes an element from each array and returns an int. If it evaluates to a non-zero value iteration is stopped and that value is returned.

array1 : 'T[]

The first input array.

array2 : 'T[]

The second input array.

Returns: int

Returns the first non-zero result from the comparison function. If the first array has a larger element, the return value is always positive. If the second array has a larger element, the return value is always negative. When the elements are equal in the two arrays, 1 is returned if the first array is longer, 0 is returned if they are equal in length, and -1 is returned when the second array is longer.

ArgumentNullException Thrown when either of the input arrays is null.
Example

 let closerToNextDozen a b =
   (a % 12).CompareTo(b % 12)

 let input1 = [| 1; 10 |]
 let input2 = [| 1; 10 |]

 (input1, input2) ||> Array.compareWith closerToNextDozen
Evaluates to 0

Example

 let closerToNextDozen a b =
   (a % 12).CompareTo(b % 12)

 let input1 = [| 1; 5 |]
 let input2 = [| 1; 8 |]

 (input1, input2) ||> Array.compareWith closerToNextDozen
Evaluates to -1

Example

 let closerToNextDozen a b =
   (a % 12).CompareTo(b % 12)

 let input1 = [| 1; 11 |]
 let input2 = [| 1; 13 |]

 (input1, input2) ||> Array.compareWith closerToNextDozen
Evaluates to 1

Example

 let closerToNextDozen a b =
   (a % 12).CompareTo(b % 12)

 let input1 = [| 1; 2 |]
 let input2 = [| 1 |]

 (input1, input2) ||> Array.compareWith closerToNextDozen
Evaluates to 1

Example

 let closerToNextDozen a b =
   (a % 12).CompareTo(b % 12)

 let input1 = [| 1 |]
 let input2 = [| 1; 2 |]

 (input1, input2) ||> Array.compareWith closerToNextDozen
Evaluates to -1

Array.concat arrays

Full Usage: Array.concat arrays

Parameters:
    arrays : seq<'T[]> - The input sequence of arrays.

Returns: 'T[] The concatenation of the sequence of input arrays.

Builds a new array that contains the elements of each of the given sequence of arrays.

arrays : seq<'T[]>

The input sequence of arrays.

Returns: 'T[]

The concatenation of the sequence of input arrays.

ArgumentNullException Thrown when the input sequence is null.
Example

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

 inputs |> Array.concat
Evaluates to [| 1; 2; 3; 4; 5 |]

Array.contains value array

Full Usage: Array.contains value array

Parameters:
    value : 'T - The value to locate in the input array.
    array : 'T[] - The input array.

Returns: bool True if the input array contains the specified element; false otherwise.
Modifiers: inline
Type parameters: 'T

Tests if the array contains the specified element.

value : 'T

The value to locate in the input array.

array : 'T[]

The input array.

Returns: bool

True if the input array contains the specified element; false otherwise.

ArgumentNullException Thrown when the input array is null.
Example

 [| 1; 2 |] |> Array.contains 2 // evaluates to true
 [| 1; 2 |] |> Array.contains 5 // evaluates to false

Array.copy array

Full Usage: Array.copy array

Parameters:
    array : 'T[] - The input array.

Returns: 'T[] A copy of the input array.

Builds a new array that contains the elements of the given array.

array : 'T[]

The input array.

Returns: 'T[]

A copy of the input array.

ArgumentNullException Thrown when the input array is null.
Example

 let source = [| 12; 13; 14 |]

 Array.copy source
Evaluates to a new array containing[| 12; 13; 14 |].

Array.countBy projection array

Full Usage: Array.countBy projection array

Parameters:
    projection : 'T -> 'Key - A function transforming each item of the input array into a key to be compared against the others.
    array : 'T[] - The input array.

Returns: ('Key * int)[] The result array.

Applies a key-generating function to each element of an array and returns an array yielding unique keys and their number of occurrences in the original array.

projection : 'T -> 'Key

A function transforming each item of the input array into a key to be compared against the others.

array : 'T[]

The input array.

Returns: ('Key * int)[]

The result array.

ArgumentNullException Thrown when the input array is null.
Example

 type Foo = { Bar: string }

 let inputs = [| {Bar = "a"}; {Bar = "b"}; {Bar = "a"} |]

 inputs |> Array.countBy (fun foo -> foo.Bar)
Evaluates to [| ("a", 2); ("b", 1) |]

Array.create count value

Full Usage: Array.create count value

Parameters:
    count : int - The length of the array to create.
    value : 'T - The value for the elements.

Returns: 'T[] The created array.

Creates an array whose elements are all initially the given value.

count : int

The length of the array to create.

value : 'T

The value for the elements.

Returns: 'T[]

The created array.

ArgumentException Thrown when count is negative.
Example

 Array.create 4 "a"
Evaluates to a new array containing[| "a"; "a"; "a"; "a" |].

Example

 let cell = ref "a"
 let array = Array.create 2 cell
 cell.Value <- "b"
Before evaluation of the last line, array contains[| { contents = "a"}; { contents = "a"} |]. After evaluation of the last line array contains[| { contents = "b"}; { contents = "b"} |]. Note each entry in the array is the same mutable cell object.

Array.distinct array

Full Usage: Array.distinct array

Parameters:
    array : 'T[] - The input array.

Returns: 'T[] The result array.

Returns an array that contains no duplicate entries according to generic hash and equality comparisons on the entries. If an element occurs multiple times in the array then the later occurrences are discarded.

array : 'T[]

The input array.

Returns: 'T[]

The result array.

ArgumentNullException Thrown when the input array is null.
Example

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

 input |> Array.distinct
Evaluates to [| 1; 2; 3 |]

Array.distinctBy projection array

Full Usage: Array.distinctBy projection array

Parameters:
    projection : 'T -> 'Key - A function transforming the array items into comparable keys.
    array : 'T[] - The input array.

Returns: 'T[] The result array.

Returns an array that contains no duplicate entries according to the generic hash and equality comparisons on the keys returned by the given key-generating function. If an element occurs multiple times in the array then the later occurrences are discarded.

projection : 'T -> 'Key

A function transforming the array items into comparable keys.

array : 'T[]

The input array.

Returns: 'T[]

The result array.

ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.distinctBy (fun foo -> foo.Bar)
Evaluates to [| { Bar = 1 }; { Bar = 2 }; { Bar = 3 } |]

Array.empty

Full Usage: Array.empty

Returns: 'T[] The empty array.

Returns an empty array of the given type.

Returns: 'T[]

The empty array.

Example

 Array.empty // Evaluates to [| |]

Array.exactlyOne array

Full Usage: Array.exactlyOne array

Parameters:
    array : 'T[] - The input array.

Returns: 'T The only element of the array.

Returns the only element of the array.

array : 'T[]

The input array.

Returns: 'T

The only element of the array.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when the input does not have precisely one element.
Example

 let inputs = [| "banana" |]

 inputs |> Array.exactlyOne
Evaluates to banana

Example

 let inputs = [| "pear"; "banana" |]

 inputs |> Array.exactlyOne
Throws ArgumentException

Example

 let inputs: int[] = [| |]

 inputs |> Array.exactlyOne
Throws ArgumentException

Array.except itemsToExclude array

Full Usage: Array.except itemsToExclude array

Parameters:
    itemsToExclude : seq<'T> - A sequence whose elements that also occur in the input array will cause those elements to be removed from the result.
    array : 'T[] - An array whose elements that are not also in itemsToExclude will be returned.

Returns: 'T[] An array that contains the distinct elements of array that do not appear in itemsToExclude.

Returns a new list with the distinct elements of the input array which do not appear in the itemsToExclude sequence, using generic hash and equality comparisons to compare values.

itemsToExclude : seq<'T>

A sequence whose elements that also occur in the input array will cause those elements to be removed from the result.

array : 'T[]

An array whose elements that are not also in itemsToExclude will be returned.

Returns: 'T[]

An array that contains the distinct elements of array that do not appear in itemsToExclude.

ArgumentNullException Thrown when either itemsToExclude or array is null.
Example

 let original = [| 1; 2; 3; 4; 5 |]
 let itemsToExclude = [| 1; 3; 5 |]

 original |> Array.except itemsToExclude
Evaluates to [| 2; 4 |]

Array.exists predicate array

Full Usage: Array.exists predicate array

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

Returns: bool True if any result from predicate is true.

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

The predicate is applied to the elements of the input array. If any application returns true then the overall result is true and no further elements are tested. Otherwise, false is returned.

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: bool

True if any result from predicate is true.

ArgumentNullException Thrown when the input array is null.
Example

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

 input |> Array.exists (fun elm -> elm % 4 = 0)
Evaluates to true

Example

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

 input |> Array.exists (fun elm -> elm % 6 = 0)
Evaluates to false

Array.exists2 predicate array1 array2

Full Usage: Array.exists2 predicate array1 array2

Parameters:
    predicate : 'T1 -> 'T2 -> bool - The function to test the input elements.
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.

Returns: bool True if any result from predicate is true.

Tests if any pair of corresponding elements of the arrays satisfies the given predicate.

The predicate is applied to matching elements in the two collections up to the lesser of the two lengths of the collections. If any application returns true then the overall result is true and no further elements are tested. Otherwise, if one collections is longer than the other then the ArgumentException exception is raised. Otherwise, false is returned.

predicate : 'T1 -> 'T2 -> bool

The function to test the input elements.

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

Returns: bool

True if any result from predicate is true.

ArgumentNullException Thrown when either of the input arrays is null.
ArgumentException Thrown when the input arrays differ in length.
Example

 let inputs1 = [| 1; 2 |]
 let inputs2 = [| 1; 2; 0 |]

 (inputs1, inputs2) ||> Array.exists2 (fun a b -> a > b)
Evaluates to false

Example

 let inputs1 = [| 1; 4 |]
 let inputs2 = [| 1; 3; 5 |]

 (inputs1, inputs2) ||> Array.exists2 (fun a b -> a > b)
Evaluates to true

Array.fill target targetIndex count value

Full Usage: Array.fill target targetIndex count value

Parameters:
    target : 'T[] - The target array.
    targetIndex : int - The index of the first element to set.
    count : int - The number of elements to set.
    value : 'T - The value to set.

Fills a range of elements of the array with the given value.

target : 'T[]

The target array.

targetIndex : int

The index of the first element to set.

count : int

The number of elements to set.

value : 'T

The value to set.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when either targetIndex or count is negative.
Example

 let target = [| 0; 1; 2; 3; 4; 5 |]

 Array.fill target 3 2 100
After evaluation target contains [| 0; 1; 2; 100; 100; 5 |].

Array.filter predicate array

Full Usage: Array.filter predicate array

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

Returns: 'T[] An array containing the elements for which the given predicate returns true.

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

The input array.

Returns: 'T[]

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

ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.filter (fun elm -> elm % 2 = 0)
Evaluates to [| 2; 4 |]

Array.find predicate array

Full Usage: Array.find predicate array

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

Returns: 'T The first element for which predicate returns true.

Returns the first element for which the given function returns 'true'. Raise KeyNotFoundException if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: 'T

The first element for which predicate returns true.

ArgumentNullException Thrown when the input array is null.
KeyNotFoundException Thrown if predicate never returns true.
Example

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

 inputs |> Array.find (fun elm -> elm % 2 = 0)
Evaluates to 2

Example

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

 inputs |> Array.find (fun elm -> elm % 6 = 0)
Throws KeyNotFoundException

Array.findBack predicate array

Full Usage: Array.findBack predicate array

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

Returns: 'T The last element for which predicate returns true.

Returns the last element for which the given function returns 'true'. Raise KeyNotFoundException if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: 'T

The last element for which predicate returns true.

KeyNotFoundException Thrown if predicate never returns true.
ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.findBack (fun elm -> elm % 2 = 0)
Evaluates to 4

Example

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

 inputs |> Array.findBack (fun elm -> elm % 6 = 0)
Throws KeyNotFoundException

Array.findIndex predicate array

Full Usage: Array.findIndex predicate array

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

Returns: int The index of the first element in the array that satisfies the given predicate.

Returns the index of the first element in the array that satisfies the given predicate. Raise KeyNotFoundException if none of the elements satisfy the predicate.

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: int

The index of the first element in the array that satisfies the given predicate.

KeyNotFoundException Thrown if predicate never returns true.
ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.findIndex (fun elm -> elm % 2 = 0)
Evaluates to 1

Example

 let inputs = [| 1; 2; 3; 4; 5 |]
 inputs |> Array.findIndex (fun elm -> elm % 6 = 0)
Throws KeyNotFoundException

Array.findIndexBack predicate array

Full Usage: Array.findIndexBack predicate array

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

Returns: int The index of the last element in the array that satisfies the given predicate.

Returns the index of the last element in the array that satisfies the given predicate. Raise KeyNotFoundException if none of the elements satisfy the predicate.

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: int

The index of the last element in the array that satisfies the given predicate.

KeyNotFoundException Thrown if predicate never returns true.
ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.findIndex (fun elm -> elm % 2 = 0)
Evaluates to 3

Example

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

 inputs |> Array.findIndex (fun elm -> elm % 6 = 0)
Throws KeyNotFoundException

Array.fold folder state array

Full Usage: Array.fold folder state array

Parameters:
    folder : 'State -> 'T -> 'State - The function to update the state given the input elements.
    state : 'State - The initial state.
    array : 'T[] - The input array.

Returns: 'State The final state.

Applies a function to each element of the collection, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN then computes f (... (f s i0)...) iN

folder : 'State -> 'T -> 'State

The function to update the state given the input elements.

state : 'State

The initial state.

array : 'T[]

The input array.

Returns: 'State

The final state.

ArgumentNullException Thrown when the input array is null.
Example

 type Charge =
     | In of int
     | Out of int

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

 (0, inputs) ||> Array.fold (fun acc charge ->
     match charge with
     | In i -> acc + i
     | Out o -> acc - o)
Evaluates to 2

Array.fold2 folder state array1 array2

Full Usage: Array.fold2 folder state array1 array2

Parameters:
    folder : 'State -> 'T1 -> 'T2 -> 'State - The function to update the state given the input elements.
    state : 'State - The initial state.
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.

Returns: 'State The final state.

Applies a function to pairs of elements drawn from the two collections, left-to-right, threading an accumulator argument through the computation. The two input arrays must have the same lengths, otherwise an ArgumentException is raised.

folder : 'State -> 'T1 -> 'T2 -> 'State

The function to update the state given the input elements.

state : 'State

The initial state.

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

Returns: 'State

The final state.

ArgumentNullException Thrown when either of the input arrays is null.
ArgumentException Thrown when the input arrays differ in length.
Example

 type CoinToss = Head | Tails

 let data1 = [| Tails; Head; Tails |]
 let data2 = [| Tails; Head; Head |]

 (0, data1, data2) |||> Array.fold2 (fun acc a b ->
     match (a, b) with
     | Head, Head -> acc + 1
     | Tails, Tails -> acc + 1
     | _ -> acc - 1)
Evaluates to 1

Array.foldBack folder array state

Full Usage: Array.foldBack folder array state

Parameters:
    folder : 'T -> 'State -> 'State - The function to update the state given the input elements.
    array : 'T[] - The input array.
    state : 'State - The initial state.

Returns: 'State The state object after the folding function is applied to each element of the array.

Applies a function to each element of the array, starting from the end, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN then computes f i0 (...(f iN s))

folder : 'T -> 'State -> 'State

The function to update the state given the input elements.

array : 'T[]

The input array.

state : 'State

The initial state.

Returns: 'State

The state object after the folding function is applied to each element of the array.

ArgumentNullException Thrown when the input array is null.
Example

 type Count =
   { Positive: int
     Negative: int
     Text: string }

 let sequence = [| 1; 0; -1; -2; 3 |]
 let initialState = {Positive = 0; Negative = 0; Text = "" }

 (sequence, initialState) ||> Array.foldBack (fun a acc  ->
     let text = acc.Text + " " + string a
     if a >= 0 then
         { acc with
             Positive = acc.Positive + 1
             Text = text }
     else
         { acc with
             Negative = acc.Negative + 1
             Text = text })
Evaluates to
 { Positive = 2
   Negative = 3
   Text = " 3 -2 -1 0 1" }

Array.foldBack2 folder array1 array2 state

Full Usage: Array.foldBack2 folder array1 array2 state

Parameters:
    folder : 'T1 -> 'T2 -> 'State -> 'State - The function to update the state given the input elements.
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.
    state : 'State - The initial state.

Returns: 'State The final state.

Apply a function to pairs of elements drawn from the two collections, right-to-left, threading an accumulator argument through the computation. The two input arrays must have the same lengths, otherwise an ArgumentException is raised.

folder : 'T1 -> 'T2 -> 'State -> 'State

The function to update the state given the input elements.

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

state : 'State

The initial state.

Returns: 'State

The final state.

ArgumentNullException Thrown when either of the input arrays is null.
ArgumentException Thrown when the input arrays differ in length.
Example

Count the positives, negatives and accumulate some text from back to front:
 type Count =
   { Positive: int
     Negative: int
     Text: string }

 let inputs1 = [| -1; -2; -3 |]
 let inputs2 = [| 3; 2; 1 |]
 let initialState = {Positive = 0; Negative = 0; Text = ""}

 (inputs1, inputs2, initialState) |||> Array.foldBack2 (fun a b acc  ->
     let text = acc.Text + "(" + string a + "," + string b + ") "
     if a + b >= 0 then
         { acc with
             Positive = acc.Positive + 1
             Text = text }
     else
         { acc with
             Negative = acc.Negative + 1
             Text = text }
 )
Evaluates to
 { Positive = 2
   Negative = 1
   Text = "(-3,1) (-2,2) (-1,3) " }

Array.forall predicate array

Full Usage: Array.forall predicate array

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

Returns: bool True if all of the array elements satisfy the predicate.

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

The predicate is applied to the elements of the input collection. If any application returns false then the overall result is false and no further elements are tested. Otherwise, true is returned.

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: bool

True if all of the array elements satisfy the predicate.

ArgumentNullException Thrown when the input array is null.
Example

 let isEven a = a % 2 = 0

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

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

Array.forall2 predicate array1 array2

Full Usage: Array.forall2 predicate array1 array2

Parameters:
    predicate : 'T1 -> 'T2 -> bool - The function to test the input elements.
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.

Returns: bool True if all of the array elements satisfy the predicate.

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

The predicate is applied to matching elements in the two collections up to the lesser of the two lengths of the collections. If any application returns false then the overall result is false and no further elements are tested. Otherwise, if one collection is longer than the other then the ArgumentException exception is raised. Otherwise, true is returned.

predicate : 'T1 -> 'T2 -> bool

The function to test the input elements.

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

Returns: bool

True if all of the array elements satisfy the predicate.

ArgumentNullException Thrown when either of the input arrays is null.
ArgumentException Thrown when the input arrays differ in length.
Example

 let inputs1 = [| 1; 2; 3 |]
 let inputs2 = [| 1; 2; 3 |]

 (inputs1, inputs2) ||> Array.forall2 (=)
Evaluates to true.

Example

 let items1 = [| 2017; 1; 1 |]
 let items2 = [| 2019; 19; 8 |]

 (items1, items2) ||> Array.forall2 (=)
Evaluates to false.

Example

 let items1 = [| 1; 2; 3 |]
 let items2 = [| 1; 2 |]

 (items1, items2) ||> Array.forall2 (=)
Throws ArgumentException.

Array.get array index

Full Usage: Array.get array index

Parameters:
    array : 'T[] - The input array.
    index : int - The input index.

Returns: 'T The value of the array at the given index.

Gets an element from an array.

Normally the syntax array[index] is preferred.

array : 'T[]

The input array.

index : int

The input index.

Returns: 'T

The value of the array at the given index.

NullReferenceException Thrown when the input array is null.
IndexOutOfRangeException Thrown when the index is negative or the input array does not contain enough elements.
Example

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

 Array.get inputs 1
Evaluates to "b"

Example

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

 Array.get inputs 4
Throws IndexOutOfRangeException

Array.groupBy projection array

Full Usage: Array.groupBy projection array

Parameters:
    projection : 'T -> 'Key - A function that transforms an element of the array into a comparable key.
    array : 'T[] - The input array.

Returns: ('Key * 'T[])[] The result array.

Applies a key-generating function to each element of an array 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[]

The input array.

Returns: ('Key * 'T[])[]

The result array.

ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.groupBy (fun n -> n % 2)
Evaluates to [| (1, [| 1; 3; 5 |]); (0, [| 2; 4 |]) |]

Array.head array

Full Usage: Array.head array

Parameters:
    array : 'T[] - The input array.

Returns: 'T The first element of the array.

Returns the first element of the array.

array : 'T[]

The input array.

Returns: 'T

The first element of the array.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when the input array is empty.
Example

 let inputs = [| "banana"; "pear" |]

 inputs |> Array.head
Evaluates to banana

Example

 [| |] |> Array.head
Throws ArgumentException

Array.indexed array

Full Usage: Array.indexed array

Parameters:
    array : 'T[] - The input array.

Returns: (int * 'T)[] The array of indexed elements.

Builds a new array whose elements are the corresponding elements of the input array paired with the integer index (from 0) of each element.

array : 'T[]

The input array.

Returns: (int * 'T)[]

The array of indexed elements.

ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.indexed
Evaluates to [| (0, "a"); (1, "b"); (2, "c") |]

Array.init count initializer

Full Usage: Array.init count initializer

Parameters:
    count : int - The number of elements to initialize.
    initializer : int -> 'T - The function to generate the initial values for each index.

Returns: 'T[] The created array.
Modifiers: inline
Type parameters: 'T

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

count : int

The number of elements to initialize.

initializer : int -> 'T

The function to generate the initial values for each index.

Returns: 'T[]

The created array.

ArgumentException Thrown when count is negative.
Example

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

Example

 Array.init -5 (fun v -> v + 5)
Throws ArgumentException

Array.insertAt index value source

Full Usage: Array.insertAt index value source

Parameters:
    index : int - The index where the item should be inserted.
    value : 'T - The value to insert.
    source : 'T[] - The input array.

Returns: 'T[] The result array.

Return a new array with a new item inserted before the given index.

index : int

The index where the item should be inserted.

value : 'T

The value to insert.

source : 'T[]

The input array.

Returns: 'T[]

The result array.

ArgumentException Thrown when index is below 0 or greater than source.Length.
Example

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

 inputs |> Array.insertAt 1 9
Evaluates to [| 0; 9; 1; 2 |].

Array.insertManyAt index values source

Full Usage: Array.insertManyAt index values source

Parameters:
    index : int - The index where the items should be inserted.
    values : seq<'T> - The values to insert.
    source : 'T[] - The input array.

Returns: 'T[] The result array.

Return a new array with new items inserted before the given index.

index : int

The index where the items should be inserted.

values : seq<'T>

The values to insert.

source : 'T[]

The input array.

Returns: 'T[]

The result array.

ArgumentException Thrown when index is below 0 or greater than source.Length.
Example

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

 inputs |> Array.insertManyAt 1 [8; 9]
Evaluates to [| 0; 8; 9; 1; 2 |].

Array.isEmpty array

Full Usage: Array.isEmpty array

Parameters:
    array : 'T[] - The input array.

Returns: bool True if the array is empty.

Returns true if the given array is empty, otherwise false.

array : 'T[]

The input array.

Returns: bool

True if the array is empty.

ArgumentNullException Thrown when the input array is null.
Example

 [| |] |> Array.isEmpty
Evaluates to true

Example

 [| "pear"; "banana" |] |> Array.isEmpty
Evaluates to false

Array.item index array

Full Usage: Array.item index array

Parameters:
    index : int - The input index.
    array : 'T[] - The input array.

Returns: 'T The value of the array at the given index.

Gets an element from an array.

Normally the syntax array[index] is preferred.

index : int

The input index.

array : 'T[]

The input array.

Returns: 'T

The value of the array at the given index.

NullReferenceException Thrown when the input array is null.
IndexOutOfRangeException Thrown when the index is negative or the input array does not contain enough elements.
Example

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

 inputs |> Array.item 1
Evaluates to "b"

Example

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

 inputs |> Array.item 4
Throws ArgumentException

Array.iter action array

Full Usage: Array.iter action array

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

Modifiers: inline
Type parameters: 'T

Applies the given function to each element of the array.

action : 'T -> unit

The function to apply.

array : 'T[]

The input array.

ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.iter (printfn "%s")
Evaluates to unit and prints
 a
 b
 c
in the console.

Array.iter2 action array1 array2

Full Usage: Array.iter2 action array1 array2

Parameters:
    action : 'T1 -> 'T2 -> unit - The function to apply.
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.

Applies the given function to pair of elements drawn from matching indices in two arrays. The two arrays must have the same lengths, otherwise an ArgumentException is raised.

action : 'T1 -> 'T2 -> unit

The function to apply.

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

ArgumentNullException Thrown when either of the input arrays is null.
ArgumentException Thrown when the input arrays differ in length.
Example

 let inputs1 = [| "a"; "b"; "c" |]
 let inputs2 = [| 1; 2; 3 |]

 (inputs1, inputs2) ||> Array.iter2 (printfn "%s: %i")
Evaluates to unit and prints
 a: 1
 b: 2
 c: 3
in the console.

Array.iteri action array

Full Usage: Array.iteri action array

Parameters:
    action : int -> 'T -> unit - The function to apply to each index and element.
    array : 'T[] - The input array.

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

action : int -> 'T -> unit

The function to apply to each index and element.

array : 'T[]

The input array.

ArgumentNullException Thrown when the input array is null.
Example

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

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

Array.iteri2 action array1 array2

Full Usage: Array.iteri2 action array1 array2

Parameters:
    action : int -> 'T1 -> 'T2 -> unit - The function to apply to each index and pair of elements.
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.

Applies the given function to pair of elements drawn from matching indices in two arrays, also passing the index of the elements. The two arrays must have the same lengths, otherwise an ArgumentException is raised.

action : int -> 'T1 -> 'T2 -> unit

The function to apply to each index and pair of elements.

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

ArgumentNullException Thrown when either of the input arrays is null.
ArgumentException Thrown when the input arrays differ in length.
Example

 let inputs1 = [| "a"; "b"; "c" |]
 let inputs2 = [| "banana"; "pear"; "apple" |]

 (inputs1, inputs2) ||> Array.iteri2 (fun i s1 s2 -> printfn "Index {i}: {s1} - {s2}")
Evaluates to unit and prints
 Index 0: a - banana
 Index 1: b - pear
 Index 2: c - apple
in the console.

Array.last array

Full Usage: Array.last array

Parameters:
    array : 'T[] - The input array.

Returns: 'T The last element of the array.
Modifiers: inline
Type parameters: 'T

Returns the last element of the array.

array : 'T[]

The input array.

Returns: 'T

The last element of the array.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when the input does not have any elements.
Example

 [| "pear"; "banana" |] |> Array.last
Evaluates to banana

Example

 [| |] |> Array.last
Throws ArgumentException

Array.length array

Full Usage: Array.length array

Parameters:
    array : 'T[] - The input array.

Returns: int The length of the array.

Returns the length of an array. You can also use property arr.Length.

The notation array.Length is preferred.

array : 'T[]

The input array.

Returns: int

The length of the array.

NullReferenceException Thrown when the input array is null.
Example

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

 inputs |> Array.length
Evaluates to 3

Array.map mapping array

Full Usage: Array.map mapping array

Parameters:
    mapping : 'T -> 'U - The function to transform elements of the array.
    array : 'T[] - The input array.

Returns: 'U[] The array of transformed elements.
Modifiers: inline
Type parameters: 'T, 'U

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

mapping : 'T -> 'U

The function to transform elements of the array.

array : 'T[]

The input array.

Returns: 'U[]

The array of transformed elements.

ArgumentNullException Thrown when the input array is null.
Example

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

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

Array.map2 mapping array1 array2

Full Usage: Array.map2 mapping array1 array2

Parameters:
    mapping : 'T1 -> 'T2 -> 'U - The function to transform the pairs of the input elements.
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.

Returns: 'U[] The array of transformed elements.

Builds a new collection whose elements are the results of applying the given function to the corresponding elements of the two collections pairwise. The two input arrays must have the same lengths, otherwise an ArgumentException is raised.

mapping : 'T1 -> 'T2 -> 'U

The function to transform the pairs of the input elements.

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

Returns: 'U[]

The array of transformed elements.

ArgumentException Thrown when the input arrays differ in length.
ArgumentNullException Thrown when either of the input arrays is null.
Example

 let inputs1 = [| "a"; "bad"; "good" |]
 let inputs2 = [| 0; 2; 1 |]

 (inputs1, inputs2) ||> Array.map2 (fun x y -> x[y])
Evaluates to [| 'a'; 'd'; 'o' |]

Array.map3 mapping array1 array2 array3

Full Usage: Array.map3 mapping array1 array2 array3

Parameters:
    mapping : 'T1 -> 'T2 -> 'T3 -> 'U - The function to transform the pairs of the input elements.
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.
    array3 : 'T3[] - The third input array.

Returns: 'U[] The array of transformed elements.

Builds a new collection whose elements are the results of applying the given function to the corresponding triples from the three collections. The three input arrays must have the same length, otherwise an ArgumentException is raised.

mapping : 'T1 -> 'T2 -> 'T3 -> 'U

The function to transform the pairs of the input elements.

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

array3 : 'T3[]

The third input array.

Returns: 'U[]

The array of transformed elements.

ArgumentException Thrown when the input arrays differ in length.
ArgumentNullException Thrown when any of the input arrays is null.
Example

 let inputs1 = [| "a"; "t"; "ti" |]
 let inputs2 = [| "l"; "h"; "m" |]
 let inputs3 = [| "l"; "e"; "e" |]

 (inputs1, inputs2, inputs3) |||> Array.map3 (fun x y z -> x + y + z)
Evaluates to [| "all"; "the"; "time" |]

Array.mapFold mapping state array

Full Usage: Array.mapFold mapping state array

Parameters:
    mapping : 'State -> 'T -> 'Result * 'State - The function to transform elements from the input array and accumulate the final value.
    state : 'State - The initial state.
    array : 'T[] - The input array.

Returns: 'Result[] * 'State The array of transformed elements, and the final accumulated value.

Combines map and fold. Builds a new array whose elements are the results of applying the given function to each of the elements of the input array. The function is also used to accumulate a final value.

mapping : 'State -> 'T -> 'Result * 'State

The function to transform elements from the input array and accumulate the final value.

state : 'State

The initial state.

array : 'T[]

The input array.

Returns: 'Result[] * 'State

The array of transformed elements, and the final accumulated value.

ArgumentNullException Thrown when the input array is null.
Example

Accumulate the charges, and double them as well
 type Charge =
     | In of int
     | Out of int

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

 let newCharges, balance =
     (0, inputs) ||> Array.mapFold (fun acc charge ->
         match charge with
         | In i -> In (i*2), acc + i
         | Out o -> Out (o*2), acc - o)
Evaluates newCharges to [|In 2; Out 4; In 6|] and balance to 2.

Array.mapFoldBack mapping array state

Full Usage: Array.mapFoldBack mapping array state

Parameters:
    mapping : 'T -> 'State -> 'Result * 'State - The function to transform elements from the input array and accumulate the final value.
    array : 'T[] - The input array.
    state : 'State - The initial state.

Returns: 'Result[] * 'State The array of transformed elements, and the final accumulated value.

Combines map and foldBack. Builds a new array whose elements are the results of applying the given function to each of the elements of the input array. The function is also used to accumulate a final value.

mapping : 'T -> 'State -> 'Result * 'State

The function to transform elements from the input array and accumulate the final value.

array : 'T[]

The input array.

state : 'State

The initial state.

Returns: 'Result[] * 'State

The array of transformed elements, and the final accumulated value.

ArgumentNullException Thrown when the input array is null.
Example

Accumulate the charges from back to front, and double them as well

 type Charge =
     | In of int
     | Out of int

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

 let newCharges, balance =
     (inputs, 0) ||> Array.mapFoldBack (fun charge acc ->
         match charge with
         | In i -> In (i*2), acc + i
         | Out o -> Out (o*2), acc - o)
Evaluates newCharges to [|In 2; Out 4; In 6|] and balance to 2.

Array.mapi mapping array

Full Usage: Array.mapi mapping array

Parameters:
    mapping : int -> 'T -> 'U - The function to transform elements and their indices.
    array : 'T[] - The input array.

Returns: 'U[] The array of transformed elements.

Builds 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, starting at zero.

mapping : int -> 'T -> 'U

The function to transform elements and their indices.

array : 'T[]

The input array.

Returns: 'U[]

The array of transformed elements.

ArgumentNullException Thrown when the input array is null.
Example

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

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

Array.mapi2 mapping array1 array2

Full Usage: Array.mapi2 mapping array1 array2

Parameters:
    mapping : int -> 'T1 -> 'T2 -> 'U - The function to transform pairs of input elements and their indices.
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.

Returns: 'U[] The array of transformed elements.

Builds a new collection whose elements are the results of applying the given function to the corresponding elements of the two collections pairwise, also passing the index of the elements. The two input arrays must have the same lengths, otherwise an ArgumentException is raised.

mapping : int -> 'T1 -> 'T2 -> 'U

The function to transform pairs of input elements and their indices.

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

Returns: 'U[]

The array of transformed elements.

ArgumentNullException Thrown when either of the input arrays is null.
ArgumentException Thrown when the input arrays differ in length.
Example

 let inputs1 = [| "a"; "bad"; "good" |]
 let inputs2 = [| 0; 2; 1 |]

 (inputs1, inputs2) ||> Array.mapi2 (fun i x y -> i, x[y])
Evaluates to [|(0, 'a'); (1, 'd'); (2, 'o')|]

Array.max array

Full Usage: Array.max array

Parameters:
    array : 'T[] - The input array.

Returns: 'T The maximum element.
Modifiers: inline
Type parameters: 'T

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

Throws ArgumentException for empty arrays.

array : 'T[]

The input array.

Returns: 'T

The maximum element.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when the input array is empty.
Example

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

 inputs |> Array.max
Evaluates to 12

Example

 let inputs: int[]= [| |]

 inputs |> Array.max
Throws System.ArgumentException.

Array.maxBy projection array

Full Usage: Array.maxBy projection array

Parameters:
    projection : 'T -> 'U - The function to transform the elements into a type supporting comparison.
    array : 'T[] - The input array.

Returns: 'T The maximum element.
Modifiers: inline
Type parameters: 'T, 'U

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

Throws ArgumentException for empty arrays.

projection : 'T -> 'U

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

array : 'T[]

The input array.

Returns: 'T

The maximum element.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when the input array is empty.
Example

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

 inputs |> Array.maxBy (fun s -> s.Length)
Evaluates to "cccc"

Example

 let inputs: string[]= [| |]

 inputs |> Array.maxBy (fun s -> s.Length)
Throws System.ArgumentException.

Array.min array

Full Usage: Array.min array

Parameters:
    array : 'T[] - The input array.

Returns: 'T The minimum element.
Modifiers: inline
Type parameters: 'T

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

Throws ArgumentException for empty arrays

array : 'T[]

The input array.

Returns: 'T

The minimum element.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when the input array is empty.
Example

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

 inputs |> Array.min
Evaluates to 10

Example

 let inputs: int[]= [| |]

 inputs |> Array.min
Throws System.ArgumentException.

Array.minBy projection array

Full Usage: Array.minBy projection array

Parameters:
    projection : 'T -> 'U - The function to transform the elements into a type supporting comparison.
    array : 'T[] - The input array.

Returns: 'T The minimum element.
Modifiers: inline
Type parameters: 'T, 'U

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

Throws ArgumentException for empty arrays.

projection : 'T -> 'U

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

array : 'T[]

The input array.

Returns: 'T

The minimum element.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when the input array is empty.
Example

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

 inputs |> Array.minBy (fun s -> s.Length)
Evaluates to "b"

Example

 let inputs: string[]= [| |]

 inputs |> Array.minBy (fun s -> s.Length)
Throws System.ArgumentException.

Array.ofList list

Full Usage: Array.ofList list

Parameters:
    list : 'T list - The input list.

Returns: 'T[] The array of elements from the list.

Builds an array from the given list.

list : 'T list

The input list.

Returns: 'T[]

The array of elements from the list.

Example

 let inputs = [ 1; 2; 5 ]

 inputs |> Array.ofList
Evaluates to [| 1; 2; 5 |].

Array.ofSeq source

Full Usage: Array.ofSeq source

Parameters:
    source : seq<'T> - The input sequence.

Returns: 'T[] The array of elements from the sequence.

Builds a new array from the given enumerable object.

source : seq<'T>

The input sequence.

Returns: 'T[]

The array of elements from the sequence.

ArgumentNullException Thrown when the input sequence is null.
Example

 let inputs = seq { 1; 2; 5 }

 inputs |> Array.ofSeq
Evaluates to [| 1; 2; 5 |].

Array.pairwise array

Full Usage: Array.pairwise array

Parameters:
    array : 'T[] - The input array.

Returns: ('T * 'T)[] The result array.

Returns an array of each element in the input array and its predecessor, with the exception of the first element which is only returned as the predecessor of the second element.

array : 'T[]

The input array.

Returns: ('T * 'T)[]

The result array.

ArgumentNullException Thrown when the input sequence is null.
Example

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

 inputs |> Array.pairwise
Evaluates to [|(1, 2); (2, 3); (3, 4)|].

Array.partition predicate array

Full Usage: Array.partition predicate array

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

Returns: 'T[] * 'T[] A pair of arrays. The first containing the elements the predicate evaluated to true, and the second containing those evaluated to false.

Splits 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[]

The input array.

Returns: 'T[] * 'T[]

A pair of arrays. The first containing the elements the predicate evaluated to true, and the second containing those evaluated to false.

ArgumentNullException Thrown when the input array is null.
Example

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

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

Array.permute indexMap array

Full Usage: Array.permute indexMap array

Parameters:
    indexMap : int -> int - The function that maps input indices to output indices.
    array : 'T[] - The input array.

Returns: 'T[] The output array.

Returns an array with all elements permuted according to the specified permutation.

indexMap : int -> int

The function that maps input indices to output indices.

array : 'T[]

The input array.

Returns: 'T[]

The output array.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when indexMap does not produce a valid permutation.
Example

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

 inputs |> Array.permute (fun x -> (x + 1) % 4)
Evaluates to [|4; 1; 2; 3|].

Array.pick chooser array

Full Usage: Array.pick chooser array

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

Returns: 'U The first result.

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 KeyNotFoundException is raised.

chooser : 'T -> 'U option

The function to generate options from the elements.

array : 'T[]

The input array.

Returns: 'U

The first result.

ArgumentNullException Thrown when the input array is null.
KeyNotFoundException Thrown if every result from chooser is None.
Example

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

 input |> Array.pick (fun n -> if n % 2 = 0 then Some (string n) else None)
Evaluates to "2".

Example

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

 input |> Array.pick (fun n -> if n > 3 = 0 then Some (string n) else None)
Throws KeyNotFoundException.

Array.reduce reduction array

Full Usage: Array.reduce reduction array

Parameters:
    reduction : 'T -> 'T -> 'T - The function to reduce a pair of elements to a single element.
    array : 'T[] - The input array.

Returns: 'T The final result of the reductions.

Applies a function to each element of the array, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN then computes f (... (f i0 i1)...) iN. Raises ArgumentException if the array has size zero.

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

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

array : 'T[]

The input array.

Returns: 'T

The final result of the reductions.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when the input array is empty.
Example

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

 inputs |> Array.reduce (fun a b -> a * 10 + b)
Evaluates to 1342, by computing ((1 * 10 + 3) * 10 + 4) * 10 + 2

Array.reduceBack reduction array

Full Usage: Array.reduceBack reduction array

Parameters:
    reduction : 'T -> 'T -> 'T - A function that takes in the next-to-last element of the list and the current accumulated result to produce the next accumulated result.
    array : 'T[] - The input array.

Returns: 'T The final result of the reductions.

Applies a function to each element of the array, starting from the end, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN then computes f i0 (...(f iN-1 iN)).

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

A function that takes in the next-to-last element of the list and the current accumulated result to produce the next accumulated result.

array : 'T[]

The input array.

Returns: 'T

The final result of the reductions.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when the input array is empty.
Example

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

 inputs |> Array.reduceBack (fun a b -> a + b * 10)
Evaluates to 2431, by computing 1 + (3 + (4 + 2 * 10) * 10) * 10

Array.removeAt index source

Full Usage: Array.removeAt index source

Parameters:
    index : int - The index of the item to be removed.
    source : 'T[] - The input array.

Returns: 'T[] The result array.

Return a new array with the item at a given index removed.

index : int

The index of the item to be removed.

source : 'T[]

The input array.

Returns: 'T[]

The result array.

ArgumentException Thrown when index is outside 0..source.Length - 1
Example

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

 inputs |> Array.removeAt 1
Evaluates to [| 0; 2 |].

Array.removeManyAt index count source

Full Usage: Array.removeManyAt index count source

Parameters:
    index : int - The index of the item to be removed.
    count : int - The number of items to remove.
    source : 'T[] - The input array.

Returns: 'T[] The result array.

Return a new array with the number of items starting at a given index removed.

index : int

The index of the item to be removed.

count : int

The number of items to remove.

source : 'T[]

The input array.

Returns: 'T[]

The result array.

ArgumentException Thrown when index is outside 0..source.Length - count
Example

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

 inputs |> Array.removeManyAt 1 2
Evaluates to [| 0; 3 |].

Array.replicate count initial

Full Usage: Array.replicate count initial

Parameters:
    count : int - The number of elements to replicate.
    initial : 'T - The value to replicate

Returns: 'T[] The generated array.

Creates an array by replicating the given initial value.

count : int

The number of elements to replicate.

initial : 'T

The value to replicate

Returns: 'T[]

The generated array.

ArgumentException Thrown when count is negative.
Example

 Array.replicate 3 "a"
Evaluates to [| "a"; "a"; "a" |].

Array.rev array

Full Usage: Array.rev array

Parameters:
    array : 'T[] - The input array.

Returns: 'T[] The reversed array.

Returns a new array with the elements in reverse order.

array : 'T[]

The input array.

Returns: 'T[]

The reversed array.

ArgumentNullException Thrown when the input array is null.
Example

 Array.rev [| 0; 1; 2 |]
Evaluates to [| 2; 1; 0 |].

Array.scan folder state array

Full Usage: Array.scan folder state array

Parameters:
    folder : 'State -> 'T -> 'State - The function to update the state given the input elements.
    state : 'State - The initial state.
    array : 'T[] - The input array.

Returns: 'State[] The array of state values.

Like fold, but return the intermediary and final results.

folder : 'State -> 'T -> 'State

The function to update the state given the input elements.

state : 'State

The initial state.

array : 'T[]

The input array.

Returns: 'State[]

The array of state values.

ArgumentNullException Thrown when the input array is null.
Example

Apply a list charges and collect the running balances as each is applied:

 type Charge =
     | In of int
     | Out of int

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

 (0, inputs) ||> Array.scan (fun acc charge ->
     match charge with
     | In i -> acc + i
     | Out o -> acc - o)
Evaluates to [|0; 1; -1; 2|]. Note 0 is the intial state, 1 the next state, -1 the next state, and 2 the final state.

Array.scanBack folder array state

Full Usage: Array.scanBack folder array state

Parameters:
    folder : 'T -> 'State -> 'State - The function to update the state given the input elements.
    array : 'T[] - The input array.
    state : 'State - The initial state.

Returns: 'State[] The array of state values.

Like foldBack, but return both the intermediary and final results.

folder : 'T -> 'State -> 'State

The function to update the state given the input elements.

array : 'T[]

The input array.

state : 'State

The initial state.

Returns: 'State[]

The array of state values.

ArgumentNullException Thrown when the input array is null.
Example

Apply a list charges from back to front, and collect the running balances as each is applied:

 type Charge =
     | In of int
     | Out of int

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

 (inputs, 0) ||> Array.scanBack (fun charge acc ->
     match charge with
     | In i -> acc + i
     | Out o -> acc - o)
Evaluates to [|2; 1; 3; 0|] by processing each input from back to front. Note 0 is the intial state, 3 the next state, 1 the next state, and 2 the final state.

Array.set array index value

Full Usage: Array.set array index value

Parameters:
    array : 'T[] - The input array.
    index : int - The input index.
    value : 'T - The input value.

Sets an element of an array.

array : 'T[]

The input array.

index : int

The input index.

value : 'T

The input value.

NullReferenceException Thrown when the input array is null.
IndexOutOfRangeException Thrown when the index is negative or the input array does not contain enough elements.
Example

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

 Array.set inputs 1 "B"
After evaluation inputs contains [| "a"; "B"; "c" |]

Example

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

 Array.set inputs 4 "d"
Throws IndexOutOfRangeException

Array.singleton value

Full Usage: Array.singleton value

Parameters:
    value : 'T - The input item.

Returns: 'T[] The result array of one item.
Modifiers: inline
Type parameters: 'T

Returns an array that contains one item only.

value : 'T

The input item.

Returns: 'T[]

The result array of one item.

Example

 Array.singleton 7
Evaluates to [| 7 |].

Array.skip count array

Full Usage: Array.skip count array

Parameters:
    count : int - The number of elements to skip. If negative the full array will be returned as a copy.
    array : 'T[] - The input array.

Returns: 'T[] A copy of the input array, after removing the first N elements.

Builds a new array that contains the elements of the given array, excluding the first N elements.

count : int

The number of elements to skip. If negative the full array will be returned as a copy.

array : 'T[]

The input array.

Returns: 'T[]

A copy of the input array, after removing the first N elements.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when count exceeds the number of elements in the array.
Example

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

 inputs |> Array.skip 2
Evaluates to [| "c"; "d" |]

Example

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

 inputs |> Array.skip 5
Throws ArgumentException.

Example

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

 inputs |> Array.skip -1
Evaluates to [| "a"; "b"; "c"; "d" |].

Array.skipWhile predicate array

Full Usage: Array.skipWhile predicate array

Parameters:
    predicate : 'T -> bool - A function that evaluates an element of the array to a boolean value.
    array : 'T[] - The input array.

Returns: 'T[] The created sub array.

Bypasses elements in an array while the given predicate returns True, and then returns the remaining elements in a new array.

predicate : 'T -> bool

A function that evaluates an element of the array to a boolean value.

array : 'T[]

The input array.

Returns: 'T[]

The created sub array.

ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.skipWhile (fun x -> x.Length < 3)
Evaluates to [|"bbb"; "cc"; "d"|]

Array.sort array

Full Usage: Array.sort array

Parameters:
    array : 'T[] - The input array.

Returns: 'T[] The sorted array.

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

This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.

array : 'T[]

The input array.

Returns: 'T[]

The sorted array.

ArgumentNullException Thrown when the input array is null.
Example

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

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

Array.sortBy projection array

Full Usage: Array.sortBy projection array

Parameters:
    projection : 'T -> 'Key - The function to transform array elements into the type that is compared.
    array : 'T[] - The input array.

Returns: 'T[] The sorted array.

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

This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.

projection : 'T -> 'Key

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

array : 'T[]

The input array.

Returns: 'T[]

The sorted array.

ArgumentNullException Thrown when the input array is null.
Example

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

 input |> Array.sortBy (fun s -> s.Length)
Evaluates to [|"a"; "dd"; "bbb"; "cccc"|].

Array.sortByDescending projection array

Full Usage: Array.sortByDescending projection array

Parameters:
    projection : 'T -> 'Key - The function to transform array elements into the type that is compared.
    array : 'T[] - The input array.

Returns: 'T[] The sorted array.
Modifiers: inline
Type parameters: 'T, 'Key

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

This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.

projection : 'T -> 'Key

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

array : 'T[]

The input array.

Returns: 'T[]

The sorted array.

Example

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

 input |> Array.sortByDescending (fun s -> s.Length)
Evaluates to [|"cccc"; "bbb"; "dd"; "a"|].

Array.sortDescending array

Full Usage: Array.sortDescending array

Parameters:
    array : 'T[] - The input array.

Returns: 'T[] The sorted array.
Modifiers: inline
Type parameters: 'T

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

This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.

array : 'T[]

The input array.

Returns: 'T[]

The sorted array.

Example

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

 input |> Array.sortDescending
Evaluates to [| 8; 6; 4; 3; 1; 1 |].

Array.sortInPlace array

Full Usage: Array.sortInPlace array

Parameters:
    array : 'T[] - The input array.

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

array : 'T[]

The input array.

ArgumentNullException Thrown when the input array is null.
Example

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

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

Array.sortInPlaceBy projection array

Full Usage: Array.sortInPlaceBy projection array

Parameters:
    projection : 'T -> 'Key - The function to transform array elements into the type that is compared.
    array : 'T[] - The input array.

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

This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.

projection : 'T -> 'Key

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

array : 'T[]

The input array.

ArgumentNullException Thrown when the input array is null.
Example

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

 array |> Array.sortInPlaceBy (fun s -> s.Length)
After evaluation array contains [|"a"; "dd"; "bbb"; "cccc"|].

Array.sortInPlaceWith comparer array

Full Usage: Array.sortInPlaceWith comparer array

Parameters:
    comparer : 'T -> 'T -> int - The function to compare pairs of array elements.
    array : 'T[] - The input array.

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

comparer : 'T -> 'T -> int

The function to compare pairs of array elements.

array : 'T[]

The input array.

ArgumentNullException Thrown when the input array is null.
Example

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.sortInPlaceWith compareEntries
After evaluation array contains [|(0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb")|].

Array.sortWith comparer array

Full Usage: Array.sortWith comparer array

Parameters:
    comparer : 'T -> 'T -> int - The function to compare pairs of array elements.
    array : 'T[] - The input array.

Returns: 'T[] The sorted array.

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

This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.

comparer : 'T -> 'T -> int

The function to compare pairs of array elements.

array : 'T[]

The input array.

Returns: 'T[]

The sorted array.

ArgumentNullException Thrown when the input array is null.
Example

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.sortWith compareEntries
Evaluates to [|(0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb")|].

Array.splitAt index array

Full Usage: Array.splitAt index array

Parameters:
    index : int - The index at which the array is split.
    array : 'T[] - The input array.

Returns: 'T[] * 'T[] The two split arrays.

Splits an array into two arrays, at the given index.

index : int

The index at which the array is split.

array : 'T[]

The input array.

Returns: 'T[] * 'T[]

The two split arrays.

ArgumentNullException Thrown when the input array is null.
InvalidOperationException Thrown when split index exceeds the number of elements in the array.
Example

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

 let front, back = input |> Array.splitAt 3
Evaluates front to [|8; 4; 3|] and back to [|1; 6; 1|].

Array.splitInto count array

Full Usage: Array.splitInto count array

Parameters:
    count : int - The maximum number of chunks.
    array : 'T[] - The input array.

Returns: 'T[][] The array split into chunks.

Splits the input array into at most count chunks.

count : int

The maximum number of chunks.

array : 'T[]

The input array.

Returns: 'T[][]

The array split into chunks.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when count is not positive.
Example

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

 inputs |> Array.splitInto 3
Evaluates to seq [| [|1; 2|]; [|3; 4|]; [|5|] |]

Example

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

 inputs |> Array.splitInto -1
Throws ArgumentException

Array.sub array startIndex count

Full Usage: Array.sub array startIndex count

Parameters:
    array : 'T[] - The input array.
    startIndex : int - The index of the first element of the sub array.
    count : int - The length of the sub array.

Returns: 'T[] The created sub array.

Builds a new array that contains the given subrange specified by starting index and length.

Slicing syntax is generally preferred, e.g.

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

 input.[2..4]

array : 'T[]

The input array.

startIndex : int

The index of the first element of the sub array.

count : int

The length of the sub array.

Returns: 'T[]

The created sub array.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when either startIndex or count is negative, or when there aren't enough elements in the input array.
Example

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

 Array.sub input 2 3
Evaluates to [| 2; 3; 4 |].

Array.sum array

Full Usage: Array.sum array

Parameters:
    array : ^T[] - The input array.

Returns: ^T The resulting sum.
Modifiers: inline
Type parameters: ^T

Returns the sum of the elements in the array.

array : ^T[]

The input array.

Returns: ^T

The resulting sum.

ArgumentNullException Thrown when the input array is null.
Example

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

 input |> Array.sum
Evaluates to 11.

Array.sumBy projection array

Full Usage: Array.sumBy projection array

Parameters:
    projection : 'T -> ^U - The function to transform the array elements into the type to be summed.
    array : 'T[] - The input array.

Returns: ^U The resulting sum.
Modifiers: inline
Type parameters: 'T, ^U

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

The input array.

Returns: ^U

The resulting sum.

ArgumentNullException Thrown when the input array is null.
Example

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

 input |> Array.sumBy (fun s -> s.Length)
Evaluates to 7.

Array.tail array

Full Usage: Array.tail array

Parameters:
    array : 'T[] - The input array.

Returns: 'T[] A new array containing the elements of the original except the first element.

Returns a new array containing the elements of the original except the first element.

array : 'T[]

The input array.

Returns: 'T[]

A new array containing the elements of the original except the first element.

ArgumentException Thrown when the array is empty.
ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| "a"; "bb"; "ccc" |]

 inputs |> Array.tail
Evaluates to [| "bb"; "ccc" |]

Array.take count array

Full Usage: Array.take count array

Parameters:
    count : int - The number of items to take.
    array : 'T[] - The input array.

Returns: 'T[] The result array.

Returns the first N elements of the array.

Throws InvalidOperationException if the count exceeds the number of elements in the array. Array.truncate returns as many items as the array contains instead of throwing an exception.

count : int

The number of items to take.

array : 'T[]

The input array.

Returns: 'T[]

The result array.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when the input array is empty.
InvalidOperationException Thrown when count exceeds the number of elements in the list.
Example

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

 inputs |> Array.take 2
Evaluates to [| "a"; "b" |]

Example

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

 inputs |> Array.take 6
Throws InvalidOperationException.

Example

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

 inputs |> Array.take 0
Evaluates to [| |].

Array.takeWhile predicate array

Full Usage: Array.takeWhile predicate array

Parameters:
    predicate : 'T -> bool - A function that evaluates to false when no more items should be returned.
    array : 'T[] - The input array.

Returns: 'T[] The result array.

Returns an array that contains all elements of the original array while the given predicate returns True, and then returns no further elements.

predicate : 'T -> bool

A function that evaluates to false when no more items should be returned.

array : 'T[]

The input array.

Returns: 'T[]

The result array.

ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| "a"; "bb"; "ccc"; "d" |]

 inputs |> Array.takeWhile (fun x -> x.Length < 3)
Evaluates to [| "a"; "bb" |]

Array.toList array

Full Usage: Array.toList array

Parameters:
    array : 'T[] - The input array.

Returns: 'T list The list of array elements.

Builds a list from the given array.

array : 'T[]

The input array.

Returns: 'T list

The list of array elements.

ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.toList
Evaluates to [ 1; 2; 5 ].

Array.toSeq array

Full Usage: Array.toSeq array

Parameters:
    array : 'T[] - The input array.

Returns: seq<'T> The sequence of array elements.

Views the given array as a sequence.

array : 'T[]

The input array.

Returns: seq<'T>

The sequence of array elements.

ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.toSeq
Evaluates to seq { 1; 2; 5 }.

Array.transpose arrays

Full Usage: Array.transpose arrays

Parameters:
    arrays : seq<'T[]> - The input sequence of arrays.

Returns: 'T[][] The transposed array.

Returns the transpose of the given sequence of arrays.

arrays : seq<'T[]>

The input sequence of arrays.

Returns: 'T[][]

The transposed array.

ArgumentNullException Thrown when the input sequence is null.
ArgumentException Thrown when the input arrays differ in length.
Example

 let inputs =
     [| [| 10; 20; 30 |]
        [| 11; 21; 31 |] |]

 inputs |> Array.transpose
Evaluates to [|[|10; 11|]; [|20; 21|]; [|30; 31|]|].

Array.truncate count array

Full Usage: Array.truncate count array

Parameters:
    count : int - The maximum number of items to return.
    array : 'T[] - The input array.

Returns: 'T[] The result array.

Returns at most N elements in a new array.

count : int

The maximum number of items to return.

array : 'T[]

The input array.

Returns: 'T[]

The result array.

ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.truncate 2
Evaluates to [| "a"; "b" |]

Example

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

 inputs |> Array.truncate 6
Evaluates to [| "a"; "b"; "c"; "d" |]

Example

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

 inputs |> Array.truncate 0
Evaluates to [| |].

Array.tryExactlyOne array

Full Usage: Array.tryExactlyOne array

Parameters:
    array : 'T[] - The input array.

Returns: 'T option The only element of the array or None.

Returns the only element of the array or None if array is empty or contains more than one element.

array : 'T[]

The input array.

Returns: 'T option

The only element of the array or None.

ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| "banana" |]

 inputs |> Array.tryExactlyOne
Evaluates to Some banana

Example

 let inputs = [| "pear"; "banana" |]

 inputs |> Array.tryExactlyOne
Evaluates to None

Example

 let inputs: int[] = [| |]

 inputs |> Array.tryExactlyOne
Evaluates to None

Array.tryFind predicate array

Full Usage: Array.tryFind predicate array

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

Returns: 'T option The first element that satisfies the predicate, or None.

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

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: 'T option

The first element that satisfies the predicate, or None.

ArgumentNullException Thrown when the input array is null.
Example

Try to find the first even number:

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

 inputs |> Array.tryFind (fun elm -> elm % 2 = 0)
Evaluates to Some 2

Example

Try to find the first even number:

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

 inputs |> Array.tryFind (fun elm -> elm % 2 = 0)
Evaluates to None

Array.tryFindBack predicate array

Full Usage: Array.tryFindBack predicate array

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

Returns: 'T option The last element that satisfies the predicate, or None.

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

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: 'T option

The last element that satisfies the predicate, or None.

ArgumentNullException Thrown when the input array is null.
Example

Try to find the first even number from the back:

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

 inputs |> Array.tryFindBack (fun elm -> elm % 2 = 0)
Evaluates to Some 4

Example

Try to find the first even number from the back:

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

 inputs |> Array.tryFindBack (fun elm -> elm % 2 = 0)
Evaluates to None

Array.tryFindIndex predicate array

Full Usage: Array.tryFindIndex predicate array

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

Returns: int option The index of the first element that satisfies the predicate, or None.

Returns the index of the first element in the array that satisfies the given predicate.

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: int option

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

ArgumentNullException Thrown when the input array is null.
Example

Try to find the index of the first even number:

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

 inputs |> Array.tryFindIndex (fun elm -> elm % 2 = 0)
Evaluates to Some 1

Example

Try to find the index of the first even number:

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

 inputs |> Array.tryFindIndex (fun elm -> elm % 2 = 0)
Evaluates to None

Array.tryFindIndexBack predicate array

Full Usage: Array.tryFindIndexBack predicate array

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

Returns: int option The index of the last element that satisfies the predicate, or None.

Returns the index of the last element in the array that satisfies the given predicate.

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: int option

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

ArgumentNullException Thrown when the input array is null.
Example

Try to find the index of the first even number from the back:

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

 inputs |> Array.tryFindIndexBack (fun elm -> elm % 2 = 0)
Evaluates to Some 3

Example

Try to find the index of the first even number from the back:

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

 inputs |> Array.tryFindIndexBack (fun elm -> elm % 2 = 0)
Evaluates to None

Array.tryHead array

Full Usage: Array.tryHead array

Parameters:
    array : 'T[] - The input array.

Returns: 'T option The first element of the array or None.

Returns the first element of the array, or None if the array is empty.

array : 'T[]

The input array.

Returns: 'T option

The first element of the array or None.

ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| "banana"; "pear" |]

 inputs |> Array.tryHead
Evaluates to Some "banana"

Example

 let inputs : int[] = [| |]

 inputs |> Array.tryHead
Evaluates to None

Array.tryItem index array

Full Usage: Array.tryItem index array

Parameters:
    index : int - The index of element to retrieve.
    array : 'T[] - The input array.

Returns: 'T option The nth element of the array or None.

Tries to find the nth element in the array. Returns None if index is negative or the input array does not contain enough elements.

index : int

The index of element to retrieve.

array : 'T[]

The input array.

Returns: 'T option

The nth element of the array or None.

ArgumentNullException Thrown when the input array is null.
Example

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

 inputs |> Array.tryItem 1
Evaluates to Some "b".

Example

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

 inputs |> Array.tryItem 4
Evaluates to None.

Array.tryLast array

Full Usage: Array.tryLast array

Parameters:
    array : 'T[] - The input array.

Returns: 'T option The last element of the array or None.

Returns the last element of the array. Return None if no such element exists.

array : 'T[]

The input array.

Returns: 'T option

The last element of the array or None.

ArgumentNullException Thrown when the input sequence is null.
Example

 [| "pear"; "banana" |] |> Array.tryLast
Evaluates to Some "banana"

Example

 [| |] |> Array.tryLast
Evaluates to None

Array.tryPick chooser array

Full Usage: Array.tryPick chooser array

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

Returns: 'U option The first transformed element that is Some(x).

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

The input array.

Returns: 'U option

The first transformed element that is Some(x).

ArgumentNullException Thrown when the input array is null.
Example

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

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

Example

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

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

Array.unfold generator state

Full Usage: Array.unfold generator state

Parameters:
    generator : 'State -> ('T * 'State) option - A function that takes in the current state and returns an option tuple of the next element of the array and the next state value.
    state : 'State - The initial state value.

Returns: 'T[] The result array.

Returns an array that contains the elements generated by the given computation. The generator is repeatedly called to build the list until it returns `None`. The given initial state argument is passed to the element generator.

generator : 'State -> ('T * 'State) option

A function that takes in the current state and returns an option tuple of the next element of the array and the next state value.

state : 'State

The initial state value.

Returns: 'T[]

The result array.

Example

 1 |> Array.unfold (fun state -> if state > 100 then None else Some (state, state * 2))
Evaluates to [| 1; 2; 4; 8; 16; 32; 64 |]

Array.unzip array

Full Usage: Array.unzip array

Parameters:
    array : ('T1 * 'T2)[] - The input array.

Returns: 'T1[] * 'T2[] The two arrays.

Splits an array of pairs into two arrays.

array : ('T1 * 'T2)[]

The input array.

Returns: 'T1[] * 'T2[]

The two arrays.

ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| (1, "one"); (2, "two") |]

 let numbers, names = inputs |> Array.unzip
Evaluates numbers to [|1; 2|] and names to [|"one"; "two"|].

Array.unzip3 array

Full Usage: Array.unzip3 array

Parameters:
    array : ('T1 * 'T2 * 'T3)[] - The input array.

Returns: 'T1[] * 'T2[] * 'T3[] The tuple of three arrays.

Splits an array of triples into three arrays.

array : ('T1 * 'T2 * 'T3)[]

The input array.

Returns: 'T1[] * 'T2[] * 'T3[]

The tuple of three arrays.

ArgumentNullException Thrown when the input array is null.
Example

 let inputs = [| (1, "one", "I"); (2, "two", "II") |]

 let numbers, names, roman = inputs |> Array.unzip3
Evaluates numbers to [|1; 2|], names to [|"one"; "two"|] and roman to [|"I"; "II"|].

Array.updateAt index value source

Full Usage: Array.updateAt index value source

Parameters:
    index : int - The index of the item to be replaced.
    value : 'T - The new value.
    source : 'T[] - The input array.

Returns: 'T[] The result array.

Return a new array with the item at a given index set to the new value.

index : int

The index of the item to be replaced.

value : 'T

The new value.

source : 'T[]

The input array.

Returns: 'T[]

The result array.

ArgumentException Thrown when index is outside 0..source.Length - 1
Example

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

 inputs |> Array.updateAt 1 9
Evaluates to [| 0; 9; 2 |].

Array.where predicate array

Full Usage: Array.where predicate array

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

Returns: 'T[] An array containing the elements for which the given predicate returns true.

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

This is identical to Array.filter.

predicate : 'T -> bool

The function to test the input elements.

array : 'T[]

The input array.

Returns: 'T[]

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

ArgumentNullException Thrown when the input array is null.
Example

Select only the even numbers:

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

 inputs |> Array.where (fun elm -> elm % 2 = 0)
Evaluates to [| 2; 4 |]

Array.windowed windowSize array

Full Usage: Array.windowed windowSize array

Parameters:
    windowSize : int - The number of elements in each window.
    array : 'T[] - The input array.

Returns: 'T[][] The result array.

Returns an array of sliding windows containing elements drawn from the input array. Each window is returned as a fresh array.

windowSize : int

The number of elements in each window.

array : 'T[]

The input array.

Returns: 'T[][]

The result array.

ArgumentNullException Thrown when the input array is null.
ArgumentException Thrown when windowSize is not positive.
Example

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

 inputs |> Array.windowed 3
Evaluates to [|[|1; 2; 3|]; [|2; 3; 4|]; [|3; 4; 5|]|]

Array.zeroCreate count

Full Usage: Array.zeroCreate count

Parameters:
    count : int - The length of the array to create.

Returns: 'T[] The created array.

Creates an array where the entries are initially the default value Unchecked.defaultof<'T>.

count : int

The length of the array to create.

Returns: 'T[]

The created array.

ArgumentException Thrown when count is negative.
Example

 let arr : int[] = Array.zeroCreate 4
Evaluates to [| 0; 0; 0; 0 |]

Array.zip array1 array2

Full Usage: Array.zip array1 array2

Parameters:
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.

Returns: ('T1 * 'T2)[] The array of tupled elements.

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

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

Returns: ('T1 * 'T2)[]

The array of tupled elements.

ArgumentNullException Thrown when either of the input arrays is null.
ArgumentException Thrown when the input arrays differ in length.
Example

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

 Array.zip numbers names
Evaluates to [| (1, "one"); (2, "two") |].

Array.zip3 array1 array2 array3

Full Usage: Array.zip3 array1 array2 array3

Parameters:
    array1 : 'T1[] - The first input array.
    array2 : 'T2[] - The second input array.
    array3 : 'T3[] - The third input array.

Returns: ('T1 * 'T2 * 'T3)[] The array of tupled elements.

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

array1 : 'T1[]

The first input array.

array2 : 'T2[]

The second input array.

array3 : 'T3[]

The third input array.

Returns: ('T1 * 'T2 * 'T3)[]

The array of tupled elements.

ArgumentNullException Thrown when any of the input arrays are null.
ArgumentException Thrown when the input arrays differ in length.
Example

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

 Array.zip3 numbers names roman
Evaluates to [|(1, "one", "I"); (2, "two", "II")|].