Contains operations for working with arrays.
See also F# Language Guide - Arrays.
Modules | Description |
Function or value | Description | ||||||
Full Usage:
Array.allPairs array1 array2
Parameters:
'T1[]
-
The first input array.
array2 : 'T2[]
-
The second input array.
Returns: ('T1 * 'T2)[]
The resulting array of pairs.
|
Example
module Array
from Microsoft.FSharp.Collections
val allPairs: array1: 'T1 array -> array2: 'T2 array -> ('T1 * 'T2) array
Evaluates to
|
||||||
Full Usage:
Array.append array1 array2
Parameters:
'T[]
-
The first input array.
array2 : 'T[]
-
The second input array.
Returns: 'T[]
The resulting array.
|
Example
module Array
from Microsoft.FSharp.Collections
val append: array1: 'T array -> array2: 'T array -> 'T array
Evaluates to [| 1; 2; 3; 4 |] .
|
||||||
Full Usage:
Array.average array
Parameters:
^T[]
-
The input array.
Returns: ^T
The average of the elements in the array.
Modifiers: inline Type parameters: ^T |
Example
module Array
from Microsoft.FSharp.Collections
val average: array: 'T array -> 'T (requires member (+) and member DivideByInt and member Zero)
Evaluates to 3.0
Example
module Array
from Microsoft.FSharp.Collections
val average: array: 'T array -> 'T (requires member (+) and member DivideByInt and member Zero)
Throws ArgumentException
|
||||||
Full Usage:
Array.averageBy projection array
Parameters:
'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 |
Example
type Foo =
{ Bar: float }
Foo.Bar: float
Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float val input: Foo array
module Array
from Microsoft.FSharp.Collections
val averageBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member DivideByInt and member Zero)
val foo: Foo
Evaluates to 3.0
Example
type Foo =
{ Bar: float }
Foo.Bar: float
Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float val input: Foo array
module Array
from Microsoft.FSharp.Collections
val averageBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member DivideByInt and member Zero)
val foo: Foo
Throws ArgumentException
|
||||||
Full Usage:
Array.blit source sourceIndex target targetIndex count
Parameters:
'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 |
Slicing syntax is generally preferred, e.g.
val source: int array
val target: int array
Example
val source: int array
val target: int array
module Array
from Microsoft.FSharp.Collections
val blit: source: 'T array -> sourceIndex: int -> target: 'T array -> targetIndex: int -> count: int -> unit
After evaluation target contains [| 0; 1; 2; 13; 14; 5 |] .
|
||||||
Full Usage:
Array.choose chooser array
Parameters:
'T -> 'U option
-
The function to generate options from the elements.
array : 'T[]
-
The input array.
Returns: 'U[]
The array of results.
|
Example
val input: int option array
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
module Array
from Microsoft.FSharp.Collections
val choose: chooser: ('T -> 'U option) -> array: 'T array -> 'U array
val id: x: 'T -> 'T
Evaluates to [| 1; 2 |]
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val choose: chooser: ('T -> 'U option) -> array: 'T array -> 'U array
val n: int
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
Evaluates to [| 2 |]
|
||||||
Full Usage:
Array.chunkBySize chunkSize array
Parameters:
int
-
The maximum size of each chunk.
array : 'T[]
-
The input array.
Returns: 'T[][]
The array divided into chunks.
|
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val chunkBySize: chunkSize: int -> array: 'T array -> 'T array array
Evaluates to [| [|1; 2|]; [|3|] |]
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val chunkBySize: chunkSize: int -> array: 'T array -> 'T array array
Throws ArgumentException
|
||||||
Full Usage:
Array.collect mapping array
Parameters:
'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.
|
Example
type Foo =
{ Bar: int array }
Foo.Bar: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val input: Foo array
module Array
from Microsoft.FSharp.Collections
val collect: mapping: ('T -> 'U array) -> array: 'T array -> 'U array
val foo: Foo
Evaluates to [| 1; 2; 3; 4 |]
Example
val input: int list list
module Array
from Microsoft.FSharp.Collections
val collect: mapping: ('T -> 'U array) -> array: 'T array -> 'U array
val id: x: 'T -> 'T
Evaluates to [| 1; 2; 3; 4 |]
|
||||||
Full Usage:
Array.compareWith comparer array1 array2
Parameters:
'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 |
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int array
val input2: int array
module Array
from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> array1: 'T array -> array2: 'T array -> int
Evaluates to 0
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int array
val input2: int array
module Array
from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> array1: 'T array -> array2: 'T array -> int
Evaluates to -1
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int array
val input2: int array
module Array
from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> array1: 'T array -> array2: 'T array -> int
Evaluates to 1
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int array
val input2: int array
module Array
from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> array1: 'T array -> array2: 'T array -> int
Evaluates to 1
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int array
val input2: int array
module Array
from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> array1: 'T array -> array2: 'T array -> int
Evaluates to -1
|
||||||
Full Usage:
Array.concat arrays
Parameters:
'T[] seq
-
The input sequence of arrays.
Returns: 'T[]
The concatenation of the sequence of input arrays.
|
Example
val inputs: int array list
module Array
from Microsoft.FSharp.Collections
val concat: arrays: 'T array seq -> 'T array
Evaluates to [| 1; 2; 3; 4; 5 |]
|
||||||
Full Usage:
Array.contains value array
Parameters:
'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 |
Example
module Array
from Microsoft.FSharp.Collections
val contains: value: 'T -> array: 'T array -> bool (requires equality)
|
||||||
Full Usage:
Array.copy array
Parameters:
'T[]
-
The input array.
Returns: 'T[]
A copy of the input array.
|
Example
val source: int array
module Array
from Microsoft.FSharp.Collections
val copy: array: 'T array -> 'T array
Evaluates to a new array containing[| 12; 13; 14 |] .
|
||||||
Full Usage:
Array.countBy projection array
Parameters:
'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.
|
Example
type Foo =
{ Bar: string }
Foo.Bar: string
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val inputs: Foo array
module Array
from Microsoft.FSharp.Collections
val countBy: projection: ('T -> 'Key) -> array: 'T array -> ('Key * int) array (requires equality)
val foo: Foo
Evaluates to [| ("a", 2); ("b", 1) |]
|
||||||
Full Usage:
Array.create count value
Parameters:
int
-
The length of the array to create.
value : 'T
-
The value for the elements.
Returns: 'T[]
The created array.
|
Example
module Array
from Microsoft.FSharp.Collections
val create: count: int -> value: 'T -> 'T array
Evaluates to a new array containing[| "a"; "a"; "a"; "a" |] .
Example
val cell: string ref
Multiple items
val ref: value: 'T -> 'T ref -------------------- type 'T ref = Ref<'T> Multiple items
val array: string ref array -------------------- type 'T array = 'T array module Array
from Microsoft.FSharp.Collections
val create: count: int -> value: 'T -> 'T array
property Ref.Value: string with get, set
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.
|
||||||
Full Usage:
Array.distinct array
Parameters:
'T[]
-
The input array.
Returns: 'T[]
The result array.
|
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val distinct: array: 'T array -> 'T array (requires equality)
Evaluates to [| 1; 2; 3 |]
|
||||||
Full Usage:
Array.distinctBy projection array
Parameters:
'T -> 'Key
-
A function transforming the array items into comparable keys.
array : 'T[]
-
The input array.
Returns: 'T[]
The result array.
|
Example
val inputs: obj array
module Array
from Microsoft.FSharp.Collections
val distinctBy: projection: ('T -> 'Key) -> array: 'T array -> 'T array (requires equality)
val foo: obj
Evaluates to [| { Bar = 1 }; { Bar = 2 }; { Bar = 3 } |]
|
||||||
Full Usage:
Array.empty
Returns: 'T[]
The empty array.
|
|||||||
Full Usage:
Array.exactlyOne array
Parameters:
'T[]
-
The input array.
Returns: 'T
The only element of the array.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val exactlyOne: array: 'T array -> 'T
Evaluates to banana
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val exactlyOne: array: 'T array -> 'T
Throws ArgumentException
Example
val inputs: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module Array
from Microsoft.FSharp.Collections
val exactlyOne: array: 'T array -> 'T
Throws ArgumentException
|
||||||
Full Usage:
Array.except itemsToExclude array
Parameters:
'T seq
-
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 .
|
Example
val original: int array
val itemsToExclude: int array
module Array
from Microsoft.FSharp.Collections
val except: itemsToExclude: 'T seq -> array: 'T array -> 'T array (requires equality)
Evaluates to [| 2; 4 |]
|
||||||
|
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.
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val exists: predicate: ('T -> bool) -> array: 'T array -> bool
val elm: int
Evaluates to true
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val exists: predicate: ('T -> bool) -> array: 'T array -> bool
val elm: int
Evaluates to false
|
||||||
|
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
Example
val inputs1: int array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val exists2: predicate: ('T1 -> 'T2 -> bool) -> array1: 'T1 array -> array2: 'T2 array -> bool
val a: int
val b: int
Evaluates to false
Example
val inputs1: int array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val exists2: predicate: ('T1 -> 'T2 -> bool) -> array1: 'T1 array -> array2: 'T2 array -> bool
val a: int
val b: int
Evaluates to true
|
||||||
|
Example
val target: int array
module Array
from Microsoft.FSharp.Collections
val fill: target: 'T array -> targetIndex: int -> count: int -> value: 'T -> unit
After evaluation target contains [| 0; 1; 2; 100; 100; 5 |] .
|
||||||
Full Usage:
Array.filter predicate array
Parameters:
'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.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val filter: predicate: ('T -> bool) -> array: 'T array -> 'T array
val elm: int
Evaluates to [| 2; 4 |]
|
||||||
Full Usage:
Array.find predicate array
Parameters:
'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.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val find: predicate: ('T -> bool) -> array: 'T array -> 'T
val elm: int
Evaluates to 2
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val find: predicate: ('T -> bool) -> array: 'T array -> 'T
val elm: int
Throws KeyNotFoundException
|
||||||
Full Usage:
Array.findBack predicate array
Parameters:
'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.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findBack: predicate: ('T -> bool) -> array: 'T array -> 'T
val elm: int
Evaluates to 4
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findBack: predicate: ('T -> bool) -> array: 'T array -> 'T
val elm: int
Throws KeyNotFoundException
|
||||||
|
![]() ![]() ![]() ![]() ![]() ![]() 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.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> array: 'T array -> int
val elm: int
Evaluates to 1
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> array: 'T array -> int
val elm: int
Throws KeyNotFoundException
|
||||||
|
![]() ![]() ![]() ![]() ![]() ![]() 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.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> array: 'T array -> int
val elm: int
Evaluates to 3
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> array: 'T array -> int
val elm: int
Throws KeyNotFoundException
|
||||||
Full Usage:
Array.fold folder state array
Parameters:
'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.
|
Example
type Charge =
| In of int
| Out of int
union case Charge.In: int -> Charge
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int union case Charge.Out: int -> Charge
val inputs: Charge array
module Array
from Microsoft.FSharp.Collections
val fold<'T,'State> : folder: ('State -> 'T -> 'State) -> state: 'State -> array: 'T array -> 'State
val acc: int
val charge: Charge
val i: int
val o: int
Evaluates to 2
|
||||||
Full Usage:
Array.fold2 folder state array1 array2
Parameters:
'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.
|
Example
type CoinToss =
| Head
| Tails
union case CoinToss.Head: CoinToss
union case CoinToss.Tails: CoinToss
val data1: CoinToss array
val data2: CoinToss array
module Array
from Microsoft.FSharp.Collections
val fold2<'T1,'T2,'State> : folder: ('State -> 'T1 -> 'T2 -> 'State) -> state: 'State -> array1: 'T1 array -> array2: 'T2 array -> 'State
val acc: int
val a: CoinToss
val b: CoinToss
Evaluates to 1
|
||||||
Full Usage:
Array.foldBack folder array state
Parameters:
'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.
|
Example
type Count =
{
Positive: int
Negative: int
Text: string
}
Count.Positive: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int Count.Negative: int
Count.Text: string
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val sequence: int array
val initialState: Count
module Array
from Microsoft.FSharp.Collections
val foldBack: folder: ('T -> 'State -> 'State) -> array: 'T array -> state: 'State -> 'State
val a: int
val acc: Count
val text: string
Evaluates to
|
||||||
Full Usage:
Array.foldBack2 folder array1 array2 state
Parameters:
'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.
|
Example
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int namespace Microsoft.FSharp.Text
Multiple items
val string: value: 'T -> string -------------------- type string = System.String module Array
from Microsoft.FSharp.Collections
val foldBack2: folder: ('T1 -> 'T2 -> 'State -> 'State) -> array1: 'T1 array -> array2: 'T2 array -> state: 'State -> 'State
Evaluates to
|
||||||
|
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.
Example
val isEven: a: int -> bool
val a: int
module Array
from Microsoft.FSharp.Collections
val forall: predicate: ('T -> bool) -> array: 'T array -> bool
|
||||||
|
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
Example
val inputs1: int array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val forall2: predicate: ('T1 -> 'T2 -> bool) -> array1: 'T1 array -> array2: 'T2 array -> bool
Evaluates to true .
Example
val items1: int array
val items2: int array
module Array
from Microsoft.FSharp.Collections
val forall2: predicate: ('T1 -> 'T2 -> bool) -> array1: 'T1 array -> array2: 'T2 array -> bool
Evaluates to false .
Example
val items1: int array
val items2: int array
module Array
from Microsoft.FSharp.Collections
val forall2: predicate: ('T1 -> 'T2 -> bool) -> array1: 'T1 array -> array2: 'T2 array -> bool
Throws ArgumentException .
|
||||||
Full Usage:
Array.get array index
Parameters:
'T[]
-
The input array.
index : int
-
The input index.
Returns: 'T
The value of the array at the given index.
|
Normally the syntax
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val get: array: 'T array -> index: int -> 'T
Evaluates to "b"
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val get: array: 'T array -> index: int -> 'T
Throws IndexOutOfRangeException
|
||||||
Full Usage:
Array.groupBy projection array
Parameters:
'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.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val groupBy: projection: ('T -> 'Key) -> array: 'T array -> ('Key * 'T array) array (requires equality)
val n: int
Evaluates to [| (1, [| 1; 3; 5 |]); (0, [| 2; 4 |]) |]
|
||||||
Full Usage:
Array.head array
Parameters:
'T[]
-
The input array.
Returns: 'T
The first element of the array.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val head: array: 'T array -> 'T
Evaluates to banana
Example
module Array
from Microsoft.FSharp.Collections
val head: array: 'T array -> 'T
Throws ArgumentException
|
||||||
Full Usage:
Array.indexed array
Parameters:
'T[]
-
The input array.
Returns: (int * 'T)[]
The array of indexed elements.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val indexed: array: 'T array -> (int * 'T) array
Evaluates to [| (0, "a"); (1, "b"); (2, "c") |]
|
||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val init: count: int -> initializer: (int -> 'T) -> 'T array
val v: int
Evaluates to [| 5; 6; 7; 8 |]
Example
module Array
from Microsoft.FSharp.Collections
val init: count: int -> initializer: (int -> 'T) -> 'T array
val v: int
Throws ArgumentException
|
||||||
Full Usage:
Array.insertAt index value source
Parameters:
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.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val insertAt: index: int -> value: 'T -> source: 'T array -> 'T array
Evaluates to [| 0; 9; 1; 2 |] .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val insertManyAt: index: int -> values: 'T seq -> source: 'T array -> 'T array
Evaluates to [| 0; 8; 9; 1; 2 |] .
|
||||||
Full Usage:
Array.isEmpty array
Parameters:
'T[]
-
The input array.
Returns: bool
True if the array is empty.
|
Example
module Array
from Microsoft.FSharp.Collections
val isEmpty: array: 'T array -> bool
Evaluates to true
Example
module Array
from Microsoft.FSharp.Collections
val isEmpty: array: 'T array -> bool
Evaluates to false
|
||||||
Full Usage:
Array.item index array
Parameters:
int
-
The input index.
array : 'T[]
-
The input array.
Returns: 'T
The value of the array at the given index.
|
Normally the syntax
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val item: index: int -> array: 'T array -> 'T
Evaluates to "b"
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val item: index: int -> array: 'T array -> 'T
Throws ArgumentException
|
||||||
Full Usage:
Array.iter action array
Parameters:
'T -> unit
-
The function to apply.
array : 'T[]
-
The input array.
Modifiers: inline Type parameters: 'T |
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val iter: action: ('T -> unit) -> array: 'T array -> unit
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||||
Full Usage:
Array.iter2 action array1 array2
Parameters:
'T1 -> 'T2 -> unit
-
The function to apply.
array1 : 'T1[]
-
The first input array.
array2 : 'T2[]
-
The second input array.
|
Example
val inputs1: string array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val iter2: action: ('T1 -> 'T2 -> unit) -> array1: 'T1 array -> array2: 'T2 array -> unit
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val iteri: action: (int -> 'T -> unit) -> array: 'T array -> unit
val i: int
val v: string
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||||
|
Example
val inputs1: string array
val inputs2: string array
module Array
from Microsoft.FSharp.Collections
val iteri2: action: (int -> 'T1 -> 'T2 -> unit) -> array1: 'T1 array -> array2: 'T2 array -> unit
val i: int
val s1: string
val s2: string
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||||
Full Usage:
Array.last array
Parameters:
'T[]
-
The input array.
Returns: 'T
The last element of the array.
Modifiers: inline Type parameters: 'T |
Example
module Array
from Microsoft.FSharp.Collections
val last: array: 'T array -> 'T
Evaluates to banana
Example
module Array
from Microsoft.FSharp.Collections
val last: array: 'T array -> 'T
Throws ArgumentException
|
||||||
Full Usage:
Array.length array
Parameters:
'T[]
-
The input array.
Returns: int
The length of the array.
|
The notation
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val length: array: 'T array -> int
Evaluates to 3
|
||||||
Full Usage:
Array.map mapping array
Parameters:
'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 |
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val x: string
property System.String.Length: int with get
Evaluates to [| 1; 3; 2 |]
|
||||||
Full Usage:
Array.map2 mapping array1 array2
Parameters:
'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.
|
Example
val inputs1: string array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val map2: mapping: ('T1 -> 'T2 -> 'U) -> array1: 'T1 array -> array2: 'T2 array -> 'U array
val x: string
val y: int
Evaluates to [| 'a'; 'd'; 'o' |]
|
||||||
Full Usage:
Array.map3 mapping array1 array2 array3
Parameters:
'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.
|
Example
val inputs1: string array
val inputs2: string array
val inputs3: string array
module Array
from Microsoft.FSharp.Collections
val map3: mapping: ('T1 -> 'T2 -> 'T3 -> 'U) -> array1: 'T1 array -> array2: 'T2 array -> array3: 'T3 array -> 'U array
val x: string
val y: string
val z: string
Evaluates to [| "all"; "the"; "time" |]
|
||||||
Full Usage:
Array.mapFold mapping state array
Parameters:
'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.
|
Example
Multiple items
val double: value: 'T -> double (requires member op_Explicit) -------------------- type double = System.Double -------------------- type double<'Measure> = float<'Measure> Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module Array
from Microsoft.FSharp.Collections
val mapFold<'T,'State,'Result> : mapping: ('State -> 'T -> 'Result * 'State) -> state: 'State -> array: 'T array -> 'Result array * 'State
Evaluates newCharges to [|In 2; Out 4; In 6|] and balance to 2 .
|
||||||
Full Usage:
Array.mapFoldBack mapping array state
Parameters:
'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.
|
ExampleAccumulate the charges from back to front, and double them as well
type Charge =
| In of int
| Out of int
union case Charge.In: int -> Charge
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int union case Charge.Out: int -> Charge
val inputs: Charge array
val newCharges: Charge array
val balance: int
module Array
from Microsoft.FSharp.Collections
val mapFoldBack: mapping: ('T -> 'State -> 'Result * 'State) -> array: 'T array -> state: 'State -> 'Result array * 'State
val charge: Charge
val acc: int
val i: int
val o: int
Evaluates newCharges to [|In 2; Out 4; In 6|] and balance to 2 .
|
||||||
Full Usage:
Array.mapi mapping array
Parameters:
int -> 'T -> 'U
-
The function to transform elements and their indices.
array : 'T[]
-
The input array.
Returns: 'U[]
The array of transformed elements.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val mapi: mapping: (int -> 'T -> 'U) -> array: 'T array -> 'U array
val i: int
val x: int
Evaluates to [| 10; 11; 12 |]
|
||||||
Full Usage:
Array.mapi2 mapping array1 array2
Parameters:
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.
|
Example
val inputs1: string array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val mapi2: mapping: (int -> 'T1 -> 'T2 -> 'U) -> array1: 'T1 array -> array2: 'T2 array -> 'U array
val i: int
val x: string
val y: int
Evaluates to [|(0, 'a'); (1, 'd'); (2, 'o')|]
|
||||||
Full Usage:
Array.max array
Parameters:
'T[]
-
The input array.
Returns: 'T
The maximum element.
Modifiers: inline Type parameters: 'T |
Throws ArgumentException for empty arrays.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val max: array: 'T array -> 'T (requires comparison)
Evaluates to 12
Example
val inputs: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module Array
from Microsoft.FSharp.Collections
val max: array: 'T array -> 'T (requires comparison)
Throws System.ArgumentException .
|
||||||
Full Usage:
Array.maxBy projection array
Parameters:
'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 |
Throws ArgumentException for empty arrays.
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val maxBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to "cccc"
Example
val inputs: string array
Multiple items
val string: value: 'T -> string -------------------- type string = System.String module Array
from Microsoft.FSharp.Collections
val maxBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Throws System.ArgumentException .
|
||||||
Full Usage:
Array.min array
Parameters:
'T[]
-
The input array.
Returns: 'T
The minimum element.
Modifiers: inline Type parameters: 'T |
Throws ArgumentException for empty arrays
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val min: array: 'T array -> 'T (requires comparison)
Evaluates to 10
Example
val inputs: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module Array
from Microsoft.FSharp.Collections
val min: array: 'T array -> 'T (requires comparison)
Throws System.ArgumentException .
|
||||||
Full Usage:
Array.minBy projection array
Parameters:
'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 |
Throws ArgumentException for empty arrays.
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val minBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to "b"
Example
val inputs: string array
Multiple items
val string: value: 'T -> string -------------------- type string = System.String module Array
from Microsoft.FSharp.Collections
val minBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Throws System.ArgumentException .
|
||||||
Full Usage:
Array.ofList list
Parameters:
'T list
-
The input list.
Returns: 'T[]
The array of elements from the list.
|
Example
val inputs: int list
module Array
from Microsoft.FSharp.Collections
val ofList: list: 'T list -> 'T array
Evaluates to [| 1; 2; 5 |] .
|
||||||
Full Usage:
Array.ofSeq source
Parameters:
'T seq
-
The input sequence.
Returns: 'T[]
The array of elements from the sequence.
|
Example
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq -------------------- type 'T seq = System.Collections.Generic.IEnumerable<'T> module Array
from Microsoft.FSharp.Collections
val ofSeq: source: 'T seq -> 'T array
Evaluates to [| 1; 2; 5 |] .
|
||||||
Full Usage:
Array.pairwise array
Parameters:
'T[]
-
The input array.
Returns: ('T * 'T)[]
The result array.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val pairwise: array: 'T array -> ('T * 'T) array
Evaluates to [|(1, 2); (2, 3); (3, 4)|] .
|
||||||
Full Usage:
Array.partition predicate array
Parameters:
'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.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val partition: predicate: ('T -> bool) -> array: 'T array -> 'T array * 'T array
val x: int
Evaluates to ([|2; 4|], [|1; 3|]) .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val permute: indexMap: (int -> int) -> array: 'T array -> 'T array
val x: int
Evaluates to [|4; 1; 2; 3|] .
|
||||||
Full Usage:
Array.pick chooser array
Parameters:
'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
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val pick: chooser: ('T -> 'U option) -> array: 'T array -> 'U
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Evaluates to "2" .
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val pick: chooser: ('T -> 'U option) -> array: 'T array -> 'U
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Throws KeyNotFoundException .
|
||||||
Full Usage:
Array.reduce reduction array
Parameters:
'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.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val reduce: reduction: ('T -> 'T -> 'T) -> array: 'T array -> 'T
val a: int
val b: int
Evaluates to 1342 , by computing ((1 * 10 + 3) * 10 + 4) * 10 + 2
|
||||||
Full Usage:
Array.reduceBack reduction array
Parameters:
'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.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val reduceBack: reduction: ('T -> 'T -> 'T) -> array: 'T array -> 'T
val a: int
val b: int
Evaluates to 2431 , by computing 1 + (3 + (4 + 2 * 10) * 10) * 10
|
||||||
Full Usage:
Array.removeAt index source
Parameters:
int
-
The index of the item to be removed.
source : 'T[]
-
The input array.
Returns: 'T[]
The result array.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val removeAt: index: int -> source: 'T array -> 'T array
Evaluates to [| 0; 2 |] .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val removeManyAt: index: int -> count: int -> source: 'T array -> 'T array
Evaluates to [| 0; 3 |] .
|
||||||
Full Usage:
Array.replicate count initial
Parameters:
int
-
The number of elements to replicate.
initial : 'T
-
The value to replicate
Returns: 'T[]
The generated array.
|
Example
module Array
from Microsoft.FSharp.Collections
val replicate: count: int -> initial: 'T -> 'T array
Evaluates to [| "a"; "a"; "a" |] .
|
||||||
Full Usage:
Array.rev array
Parameters:
'T[]
-
The input array.
Returns: 'T[]
The reversed array.
|
Example
module Array
from Microsoft.FSharp.Collections
val rev: array: 'T array -> 'T array
Evaluates to [| 2; 1; 0 |] .
|
||||||
Full Usage:
Array.scan folder state array
Parameters:
'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.
|
ExampleApply a list charges and collect the running balances as each is applied:
type Charge =
| In of int
| Out of int
union case Charge.In: int -> Charge
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int union case Charge.Out: int -> Charge
val inputs: Charge array
module Array
from Microsoft.FSharp.Collections
val scan<'T,'State> : folder: ('State -> 'T -> 'State) -> state: 'State -> array: 'T array -> 'State array
val acc: int
val charge: Charge
val i: int
val o: int
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.
|
||||||
Full Usage:
Array.scanBack folder array state
Parameters:
'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.
|
ExampleApply a list charges from back to front, and collect the running balances as each is applied:
type Charge =
| In of int
| Out of int
union case Charge.In: int -> Charge
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int union case Charge.Out: int -> Charge
val inputs: Charge array
module Array
from Microsoft.FSharp.Collections
val scanBack: folder: ('T -> 'State -> 'State) -> array: 'T array -> state: 'State -> 'State array
val charge: Charge
val acc: int
val i: int
val o: int
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.
|
||||||
Full Usage:
Array.set array index value
Parameters:
'T[]
-
The input array.
index : int
-
The input index.
value : 'T
-
The input value.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val set: array: 'T array -> index: int -> value: 'T -> unit
After evaluation inputs contains [| "a"; "B"; "c" |]
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val set: array: 'T array -> index: int -> value: 'T -> unit
Throws IndexOutOfRangeException
|
||||||
Full Usage:
Array.singleton value
Parameters:
'T
-
The input item.
Returns: 'T[]
The result array of one item.
Modifiers: inline Type parameters: 'T |
|||||||
Full Usage:
Array.skip count array
Parameters:
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.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val skip: count: int -> array: 'T array -> 'T array
Evaluates to [| "c"; "d" |]
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val skip: count: int -> array: 'T array -> 'T array
Throws ArgumentException .
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val skip: count: int -> array: 'T array -> 'T array
Evaluates to [| "a"; "b"; "c"; "d" |] .
|
||||||
Full Usage:
Array.skipWhile predicate array
Parameters:
'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.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val skipWhile: predicate: ('T -> bool) -> array: 'T array -> 'T array
val x: string
property System.String.Length: int with get
Evaluates to [|"bbb"; "cc"; "d"|]
|
||||||
Full Usage:
Array.sort array
Parameters:
'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.
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val sort: array: 'T array -> 'T array (requires comparison)
Evaluates to [| 1; 1; 3; 4; 6; 8 |] .
|
||||||
Full Usage:
Array.sortBy projection array
Parameters:
'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.
Example
val input: string array
module Array
from Microsoft.FSharp.Collections
val sortBy: projection: ('T -> 'Key) -> array: 'T array -> 'T array (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to [|"a"; "dd"; "bbb"; "cccc"|] .
|
||||||
Full Usage:
Array.sortByDescending projection array
Parameters:
'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.
Example
val input: string array
module Array
from Microsoft.FSharp.Collections
val sortByDescending: projection: ('T -> 'Key) -> array: 'T array -> 'T array (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to [|"cccc"; "bbb"; "dd"; "a"|] .
|
||||||
Full Usage:
Array.sortDescending array
Parameters:
'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.
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val sortDescending: array: 'T array -> 'T array (requires comparison)
Evaluates to [| 8; 6; 4; 3; 1; 1 |] .
|
||||||
Full Usage:
Array.sortInPlace array
Parameters:
'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.
Example
Multiple items
val array: int array -------------------- type 'T array = 'T array module Array
from Microsoft.FSharp.Collections
val sortInPlace: array: 'T array -> unit (requires comparison)
After evaluation array contains [| 1; 1; 3; 4; 6; 8 |] .
|
||||||
Full Usage:
Array.sortInPlaceBy projection array
Parameters:
'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.
Example
Multiple items
val array: string array -------------------- type 'T array = 'T array module Array
from Microsoft.FSharp.Collections
val sortInPlaceBy: projection: ('T -> 'Key) -> array: 'T array -> unit (requires comparison)
val s: string
property System.String.Length: int with get
After evaluation array contains [|"a"; "dd"; "bbb"; "cccc"|] .
|
||||||
Full Usage:
Array.sortInPlaceWith comparer array
Parameters:
'T -> 'T -> int
-
The function to compare pairs of array elements.
array : 'T[]
-
The input array.
|
ExampleThe following sorts entries using a comparison function that compares string lengths then index numbers:
val compareEntries: n1: int * s1: string -> n2: int * s2: string -> int
val n1: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val s1: string
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val n2: int
val s2: string
val c: int
val compare: e1: 'T -> e2: 'T -> int (requires comparison)
property System.String.Length: int with get
Multiple items
val array: (int * string) array -------------------- type 'T array = 'T array module Array
from Microsoft.FSharp.Collections
val sortInPlaceWith: comparer: ('T -> 'T -> int) -> array: 'T array -> unit
After evaluation array contains [|(0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb")|] .
|
||||||
Full Usage:
Array.sortWith comparer array
Parameters:
'T -> 'T -> int
-
The function to compare pairs of array elements.
array : 'T[]
-
The input array.
Returns: 'T[]
The sorted 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.
ExampleSort an array of pairs using a comparison function that compares string lengths then index numbers:
val compareEntries: n1: int * s1: string -> n2: int * s2: string -> int
val n1: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val s1: string
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val n2: int
val s2: string
val c: int
val compare: e1: 'T -> e2: 'T -> int (requires comparison)
property System.String.Length: int with get
val input: (int * string) array
module Array
from Microsoft.FSharp.Collections
val sortWith: comparer: ('T -> 'T -> int) -> array: 'T array -> 'T array
Evaluates to [|(0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb")|] .
|
||||||
Full Usage:
Array.splitAt index array
Parameters:
int
-
The index at which the array is split.
array : 'T[]
-
The input array.
Returns: 'T[] * 'T[]
The two split arrays.
|
Example
val input: int array
val front: int array
val back: int array
module Array
from Microsoft.FSharp.Collections
val splitAt: index: int -> array: 'T array -> 'T array * 'T array
Evaluates front to [|8; 4; 3|] and back to [|1; 6; 1|] .
|
||||||
Full Usage:
Array.splitInto count array
Parameters:
int
-
The maximum number of chunks.
array : 'T[]
-
The input array.
Returns: 'T[][]
The array split into chunks.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val splitInto: count: int -> array: 'T array -> 'T array array
Evaluates to seq [| [|1; 2|]; [|3; 4|]; [|5|] |]
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val splitInto: count: int -> array: 'T array -> 'T array array
Throws ArgumentException
|
||||||
|
Slicing syntax is generally preferred, e.g.
val input: int array
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val sub: array: 'T array -> startIndex: int -> count: int -> 'T array
Evaluates to [| 2; 3; 4 |] .
|
||||||
Full Usage:
Array.sum array
Parameters:
^T[]
-
The input array.
Returns: ^T
The resulting sum.
Modifiers: inline Type parameters: ^T |
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val sum: array: 'T array -> 'T (requires member (+) and member Zero)
Evaluates to 11 .
|
||||||
Full Usage:
Array.sumBy projection array
Parameters:
'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 |
Example
val input: string array
module Array
from Microsoft.FSharp.Collections
val sumBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member Zero)
val s: string
property System.String.Length: int with get
Evaluates to 7 .
|
||||||
Full Usage:
Array.tail array
Parameters:
'T[]
-
The input array.
Returns: 'T[]
A new array containing the elements of the original except the first element.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tail: array: 'T array -> 'T array
Evaluates to [| "bb"; "ccc" |]
|
||||||
Full Usage:
Array.take count array
Parameters:
int
-
The number of items to take.
array : 'T[]
-
The input array.
Returns: 'T[]
The result array.
|
Throws
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val take: count: int -> array: 'T array -> 'T array
Evaluates to [| "a"; "b" |]
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val take: count: int -> array: 'T array -> 'T array
Throws InvalidOperationException .
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val take: count: int -> array: 'T array -> 'T array
Evaluates to [| |] .
|
||||||
Full Usage:
Array.takeWhile predicate array
Parameters:
'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.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val takeWhile: predicate: ('T -> bool) -> array: 'T array -> 'T array
val x: string
property System.String.Length: int with get
Evaluates to [| "a"; "bb" |]
|
||||||
Full Usage:
Array.toList array
Parameters:
'T[]
-
The input array.
Returns: 'T list
The list of array elements.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val toList: array: 'T array -> 'T list
Evaluates to [ 1; 2; 5 ] .
|
||||||
Full Usage:
Array.toSeq array
Parameters:
'T[]
-
The input array.
Returns: 'T seq
The sequence of array elements.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val toSeq: array: 'T array -> 'T seq
Evaluates to seq { 1; 2; 5 } .
|
||||||
Full Usage:
Array.transpose arrays
Parameters:
'T[] seq
-
The input sequence of arrays.
Returns: 'T[][]
The transposed array.
|
Example
val inputs: int array array
module Array
from Microsoft.FSharp.Collections
val transpose: arrays: 'T array seq -> 'T array array
Evaluates to [|[|10; 11|]; [|20; 21|]; [|30; 31|]|] .
|
||||||
Full Usage:
Array.truncate count array
Parameters:
int
-
The maximum number of items to return.
array : 'T[]
-
The input array.
Returns: 'T[]
The result array.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val truncate: count: int -> array: 'T array -> 'T array
Evaluates to [| "a"; "b" |]
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val truncate: count: int -> array: 'T array -> 'T array
Evaluates to [| "a"; "b"; "c"; "d" |]
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val truncate: count: int -> array: 'T array -> 'T array
Evaluates to [| |] .
|
||||||
Full Usage:
Array.tryExactlyOne array
Parameters:
'T[]
-
The input array.
Returns: 'T option
The only element of the array or None.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tryExactlyOne: array: 'T array -> 'T option
Evaluates to Some banana
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tryExactlyOne: array: 'T array -> 'T option
Evaluates to None
Example
val inputs: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module Array
from Microsoft.FSharp.Collections
val tryExactlyOne: array: 'T array -> 'T option
Evaluates to None
|
||||||
|
ExampleTry to find the first even number:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFind: predicate: ('T -> bool) -> array: 'T array -> 'T option
val elm: int
Evaluates to Some 2
ExampleTry to find the first even number:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFind: predicate: ('T -> bool) -> array: 'T array -> 'T option
val elm: int
Evaluates to None
|
||||||
|
ExampleTry to find the first even number from the back:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindBack: predicate: ('T -> bool) -> array: 'T array -> 'T option
val elm: int
Evaluates to Some 4
ExampleTry to find the first even number from the back:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindBack: predicate: ('T -> bool) -> array: 'T array -> 'T option
val elm: int
Evaluates to None
|
||||||
|
ExampleTry to find the index of the first even number:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindIndex: predicate: ('T -> bool) -> array: 'T array -> int option
val elm: int
Evaluates to Some 1
ExampleTry to find the index of the first even number:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindIndex: predicate: ('T -> bool) -> array: 'T array -> int option
val elm: int
Evaluates to None
|
||||||
|
ExampleTry to find the index of the first even number from the back:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindIndexBack: predicate: ('T -> bool) -> array: 'T array -> int option
val elm: int
Evaluates to Some 3
ExampleTry to find the index of the first even number from the back:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindIndexBack: predicate: ('T -> bool) -> array: 'T array -> int option
val elm: int
Evaluates to None
|
||||||
Full Usage:
Array.tryHead array
Parameters:
'T[]
-
The input array.
Returns: 'T option
The first element of the array or None.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tryHead: array: 'T array -> 'T option
Evaluates to Some "banana"
Example
val inputs: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module Array
from Microsoft.FSharp.Collections
val tryHead: array: 'T array -> 'T option
Evaluates to None
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tryItem: index: int -> array: 'T array -> 'T option
Evaluates to Some "b" .
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tryItem: index: int -> array: 'T array -> 'T option
Evaluates to None .
|
||||||
Full Usage:
Array.tryLast array
Parameters:
'T[]
-
The input array.
Returns: 'T option
The last element of the array or None.
|
Example
module Array
from Microsoft.FSharp.Collections
val tryLast: array: 'T array -> 'T option
Evaluates to Some "banana"
Example
module Array
from Microsoft.FSharp.Collections
val tryLast: array: 'T array -> 'T option
Evaluates to None
|
||||||
|
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val tryPick: chooser: ('T -> 'U option) -> array: 'T array -> 'U option
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Evaluates to Some "2" .
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val tryPick: chooser: ('T -> 'U option) -> array: 'T array -> 'U option
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Evaluates to None .
|
||||||
Full Usage:
Array.unfold generator state
Parameters:
'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
module Array
from Microsoft.FSharp.Collections
val unfold<'T,'State> : generator: ('State -> ('T * 'State) option) -> state: 'State -> 'T array
val state: int
union case Option.None: Option<'T>
union case Option.Some: Value: 'T -> Option<'T>
Evaluates to [| 1; 2; 4; 8; 16; 32; 64 |]
|
||||||
Full Usage:
Array.unzip array
Parameters:
('T1 * 'T2)[]
-
The input array.
Returns: 'T1[] * 'T2[]
The two arrays.
|
Example
val inputs: (int * string) array
val numbers: int array
val names: string array
module Array
from Microsoft.FSharp.Collections
val unzip: array: ('T1 * 'T2) array -> 'T1 array * 'T2 array
Evaluates numbers to [|1; 2|] and names to [|"one"; "two"|] .
|
||||||
Full Usage:
Array.unzip3 array
Parameters:
('T1 * 'T2 * 'T3)[]
-
The input array.
Returns: 'T1[] * 'T2[] * 'T3[]
The tuple of three arrays.
|
Example
val inputs: (int * string * string) array
val numbers: int array
val names: string array
val roman: string array
module Array
from Microsoft.FSharp.Collections
val unzip3: array: ('T1 * 'T2 * 'T3) array -> 'T1 array * 'T2 array * 'T3 array
Evaluates numbers to [|1; 2|] , names to [|"one"; "two"|] and roman to [|"I"; "II"|] .
|
||||||
Full Usage:
Array.updateAt index value source
Parameters:
int
-
The index of the item to be replaced.
value : 'T
-
The new value.
source : 'T[]
-
The input array.
Returns: 'T[]
The result array.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val updateAt: index: int -> value: 'T -> source: 'T array -> 'T array
Evaluates to [| 0; 9; 2 |] .
|
||||||
Full Usage:
Array.where predicate array
Parameters:
'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.
|
This is identical to
ExampleSelect only the even numbers:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val where: predicate: ('T -> bool) -> array: 'T array -> 'T array
val elm: int
Evaluates to [| 2; 4 |]
|
||||||
Full Usage:
Array.windowed windowSize array
Parameters:
int
-
The number of elements in each window.
array : 'T[]
-
The input array.
Returns: 'T[][]
The result array.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val windowed: windowSize: int -> array: 'T array -> 'T array array
Evaluates to [|[|1; 2; 3|]; [|2; 3; 4|]; [|3; 4; 5|]|]
|
||||||
Full Usage:
Array.zeroCreate count
Parameters:
int
-
The length of the array to create.
Returns: 'T[]
The created array.
|
Example
val arr: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module Array
from Microsoft.FSharp.Collections
val zeroCreate: count: int -> 'T array
Evaluates to [| 0; 0; 0; 0 |]
|
||||||
Full Usage:
Array.zip array1 array2
Parameters:
'T1[]
-
The first input array.
array2 : 'T2[]
-
The second input array.
Returns: ('T1 * 'T2)[]
The array of tupled elements.
|
Example
val numbers: int array
val names: string array
module Array
from Microsoft.FSharp.Collections
val zip: array1: 'T1 array -> array2: 'T2 array -> ('T1 * 'T2) array
Evaluates to [| (1, "one"); (2, "two") |] .
|
||||||
Full Usage:
Array.zip3 array1 array2 array3
Parameters:
'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.
|
Example
val numbers: int array
val names: string array
val roman: string array
module Array
from Microsoft.FSharp.Collections
val zip3: array1: 'T1 array -> array2: 'T2 array -> array3: 'T3 array -> ('T1 * 'T2 * 'T3) array
Evaluates to [|(1, "one", "I"); (2, "two", "II")|] .
|