Array Module
Contains operations for working with arrays.
See also F# Language Guide - Arrays.
Nested modules
Modules | Description |
Provides parallel operations on arrays |
Functions and values
Function or value |
Description
|
||||||||||
|
Returns a new array that contains all pairings of elements from the first and second arrays.
Example
module Array
from Microsoft.FSharp.Collections
val allPairs: array1: 'T1 array -> array2: 'T2 array -> ('T1 * 'T2) array
Evaluates to
|
||||||||||
|
Builds a new array that contains the elements of the first array followed by the elements of the second 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 array
-
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.
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 array
-
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.
Example
type Foo =
{ Bar: float }
Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float val input: Foo array
module Array
from Microsoft.FSharp.Collections
val averageBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member DivideByInt and member Zero)
val foo: Foo
Foo.Bar: float
Evaluates to 3.0
Example
type Foo =
{ Bar: float }
Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float val input: Foo array
type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val averageBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member DivideByInt and member Zero)
val foo: Foo
Foo.Bar: float
Throws ArgumentException
|
||||||||||
Full Usage:
Array.blit source sourceIndex target targetIndex count
Parameters:
'T array
-
The source array.
sourceIndex : int
-
The starting index of the source array.
target : 'T array
-
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.
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 |] .
|
||||||||||
|
Applies the given function to each element of the array. Returns
the array comprised of the 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 |]
|
||||||||||
|
Divides the input array into chunks of size at most
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
|
||||||||||
|
For each element of the array, applies the given function. Concatenates all the results and return the combined array.
Example
type Foo =
{ Bar: int array }
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
val input: Foo array
module Array
from Microsoft.FSharp.Collections
val collect: mapping: ('T -> 'U array) -> array: 'T array -> 'U array
val foo: Foo
Foo.Bar: int array
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 array
-
The first input array.
array2 : 'T array
-
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.
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
|
||||||||||
|
Builds a new array that contains the elements of each of the given sequence of 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 |]
|
||||||||||
|
Tests if the array contains the specified element.
Example
module Array
from Microsoft.FSharp.Collections
val contains: value: 'T -> array: 'T array -> bool (requires equality)
|
||||||||||
|
Builds a new array that contains the elements of the given 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 |] .
|
||||||||||
|
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.
Example
type 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
Foo.Bar: string
Evaluates to [| ("a", 2); ("b", 1) |]
|
||||||||||
|
Creates an array whose elements are all initially the given value.
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.
|
||||||||||
|
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.
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 |]
|
||||||||||
|
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.
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 } |]
|
||||||||||
|
Returns an empty array of the given type.
Example
module Array
from Microsoft.FSharp.Collections
val empty<'T> : 'T array
|
||||||||||
Full Usage:
Array.exactlyOne array
Parameters:
'T array
-
The input array.
Returns: 'T
The only element of the array.
|
Returns 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 type 'T array = 'T array
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 array
-
An array whose elements that are not also in itemsToExclude will be returned.
Returns: 'T array
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.
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 |]
|
||||||||||
|
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.
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
|
||||||||||
|
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
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
|
||||||||||
|
Fills a range of elements of the array with the given value.
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 |] .
|
||||||||||
|
Returns a new collection containing only the elements of the collection 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 |]
|
||||||||||
|
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
|
||||||||||
|
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 array
-
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
Example
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge array
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
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 array
-
The first input array.
array2 : 'T2 array
-
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
Example
type CoinToss =
| Head
| Tails
val data1: CoinToss array
union case CoinToss.Tails: CoinToss
union case CoinToss.Head: CoinToss
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 array
-
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
Example
type Count =
{
Positive: int
Negative: int
Text: string
}
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int 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
Count.Text: string
Count.Positive: int
Count.Negative: int
Evaluates to
namespace Microsoft.FSharp.Text
|
||||||||||
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 array
-
The first input array.
array2 : 'T2 array
-
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
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
namespace Microsoft.FSharp.Text
|
||||||||||
|
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.
Example
val isEven: a: int -> bool
val a: int
module Array
from Microsoft.FSharp.Collections
val forall: predicate: ('T -> bool) -> array: 'T array -> bool
|
||||||||||
|
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
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 .
|
||||||||||
|
Gets an element from an array.
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
|
||||||||||
|
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.
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 array
-
The input array.
Returns: 'T
The first element of the array.
|
Returns 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
|
||||||||||
|
Builds a new array whose elements are the corresponding elements of the input array paired with the integer index (from 0) of each element.
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") |]
|
||||||||||
|
Creates an array given the dimension and a generator function to compute the elements.
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
|
||||||||||
|
Return a new array with a new item inserted before the given index.
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 |] .
|
||||||||||
|
Return a new array with new items inserted before the given index.
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 |] .
|
||||||||||
|
Returns true if the given array is empty, otherwise false.
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
|
||||||||||
|
Gets an element from an array.
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
|
||||||||||
|
Applies the given function to each element of the array.
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.
|
||||||||||
|
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
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.
|
||||||||||
|
Applies the given function to each element of the array. The integer passed to the function indicates the index of element.
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.
|
||||||||||
|
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
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 array
-
The input array.
Returns: 'T
The last element of the array.
Modifiers: inline Type parameters: 'T |
Returns the last element of the array.
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
|
||||||||||
|
Returns the length of an array. You can also use property arr.Length.
The notation
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val length: array: 'T array -> int
Evaluates to 3
|
||||||||||
|
Builds a new array whose elements are the results of applying the given function to each of the elements of the array.
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 |]
|
||||||||||
|
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
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 array
-
The first input array.
array2 : 'T2 array
-
The second input array.
array3 : 'T3 array
-
The third input array.
Returns: 'U array
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
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 array
-
The input array.
Returns: 'Result array * '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.
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 array
-
The input array.
state : 'State
-
The initial state.
Returns: 'Result array * '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.
ExampleAccumulate the charges from back to front, and double them as well
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge array
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
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 .
|
||||||||||
|
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.
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 array
-
The first input array.
array2 : 'T2 array
-
The second input array.
Returns: 'U array
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
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 array
-
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.
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 type 'T array = 'T array
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 array
-
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.
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 type 'T array = 'T 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
Throws System.ArgumentException .
|
||||||||||
Full Usage:
Array.min array
Parameters:
'T array
-
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
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 type 'T array = 'T array
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 array
-
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.
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 type 'T array = 'T 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
Throws System.ArgumentException .
|
||||||||||
|
Builds an array from the given list.
Example
val inputs: int list
module Array
from Microsoft.FSharp.Collections
val ofList: list: 'T list -> 'T array
Evaluates to [| 1; 2; 5 |] .
|
||||||||||
|
Builds a new array from the given enumerable object.
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 |] .
|
||||||||||
|
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.
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 array
-
The input array.
Returns: 'T array * 'T array
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.
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|]) .
|
||||||||||
|
Returns an array with all elements permuted according to the specified permutation.
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|] .
|
||||||||||
|
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.randomChoice source
Parameters:
'T array
-
The input array.
Returns: 'T
A randomly selected element from the input array.
|
Returns a random element from the given array.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to 3 .
|
||||||||||
|
Returns a random element from the given array using the specified
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to 3 .
|
||||||||||
|
Returns a random element from the given array with the specified
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to 3 .
|
||||||||||
|
Returns an array of random elements from the given array, each element can be selected multiple times.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to [| 3; 1; 3 |] .
|
||||||||||
Full Usage:
Array.randomChoicesBy randomizer count source
Parameters:
unit -> float
-
The randomizer function, must return a float number from [0.0..1.0) range.
count : int
-
The number of elements to return.
source : 'T array
-
The input array.
Returns: 'T array
An array of randomly selected elements from the input array.
|
Returns an array of random elements from the given array using the specified
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to [| 3; 1; 3 |] .
|
||||||||||
|
Returns an array of random elements from the given array with the specified
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to [| 3; 1; 3 |] .
|
||||||||||
|
Returns a random sample of elements from the given array, each element can be selected only once.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to [| 3; 1; 2 |] .
|
||||||||||
Full Usage:
Array.randomSampleBy randomizer count source
Parameters:
unit -> float
-
The randomizer function, must return a float number from [0.0..1.0) range.
count : int
-
The number of elements to return.
source : 'T array
-
The input array.
Returns: 'T array
An array of randomly selected elements from the input array.
|
Returns a random sample of elements from the given array using the specified
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to [| 3; 1; 2 |] .
|
||||||||||
|
Returns a random sample of elements from the given array with the specified
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to [| 3; 1; 2 |] .
|
||||||||||
|
Return a new array shuffled in a random order.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to [| 0; 2; 4; 3; 1 |] .
|
||||||||||
|
Return a new array shuffled in a random order using the specified
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to [| 0; 2; 4; 3; 1 |] .
|
||||||||||
|
Sorts input array in a random order by mutating the array in-place.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
After evaluation array can contain [| 0; 2; 4; 3; 1 |] .
|
||||||||||
|
Sorts input array in a random order using the specified
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
After evaluation array can contain [| 0; 2; 4; 3; 1 |] .
|
||||||||||
|
Sorts input array in a random order with the specified
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
After evaluation array can contain [| 0; 2; 4; 3; 1 |] .
|
||||||||||
|
Return a new array shuffled in a random order with the specified
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
Can evaluate to [| 0; 2; 4; 3; 1 |] .
|
||||||||||
Full Usage:
Array.reduce reduction array
Parameters:
'T -> 'T -> 'T
-
The function to reduce a pair of elements to a single element.
array : 'T array
-
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
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 array
-
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
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
|
||||||||||
|
Return a new array with the item at a given index removed.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val removeAt: index: int -> source: 'T array -> 'T array
Evaluates to [| 0; 2 |] .
|
||||||||||
|
Return a new array with the number of items starting at a given index removed.
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 |] .
|
||||||||||
|
Creates an array by replicating the given initial value.
Example
module Array
from Microsoft.FSharp.Collections
val replicate: count: int -> initial: 'T -> 'T array
Evaluates to [| "a"; "a"; "a" |] .
|
||||||||||
|
Returns a new array with the elements in reverse order.
Example
module Array
from Microsoft.FSharp.Collections
val rev: array: 'T array -> 'T array
Evaluates to [| 2; 1; 0 |] .
|
||||||||||
|
Like
ExampleApply a list charges and collect the running balances as each is applied:
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge array
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
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 initial
state, 1 the next state, -1 the next state, and 2 the final state.
|
||||||||||
|
Like
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
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge array
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
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 initial
state, 3 the next state, 1 the next state, and 2 the final state.
|
||||||||||
|
Sets an element of an array.
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 array
The result array of one item.
Modifiers: inline Type parameters: 'T |
Returns an array that contains one item only.
Example
module Array
from Microsoft.FSharp.Collections
val singleton: value: 'T -> 'T array
Evaluates to [| 7 |] .
|
||||||||||
|
Builds a new array that contains the elements of the given array, excluding 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" |] .
|
||||||||||
|
Bypasses elements in an array while the given predicate returns True, and then returns the remaining elements in a new 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"|]
|
||||||||||
|
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 |] .
|
||||||||||
|
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"|] .
|
||||||||||
|
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"|] .
|
||||||||||
|
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 |] .
|
||||||||||
|
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 array
-
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"|] .
|
||||||||||
|
Sorts the elements of an array by mutating the array in-place, using the given comparison function as the order.
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")|] .
|
||||||||||
|
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.
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")|] .
|
||||||||||
|
Splits an array into two arrays, at the given index.
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|] .
|
||||||||||
|
Splits the input array into at most
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
|
||||||||||
|
Builds a new array that contains the given subrange specified by starting index and length. 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 array
-
The input array.
Returns: ^T
The resulting sum.
Modifiers: inline Type parameters: ^T |
Returns the sum of the elements in the array.
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 array
-
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.
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 .
|
||||||||||
|
Returns 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" |]
|
||||||||||
|
Returns the first N elements of the 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 [| |] .
|
||||||||||
|
Returns an array that contains all elements of the original array while the given predicate returns True, and then returns no further elements.
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" |]
|
||||||||||
|
Builds a list from the given array.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val toList: array: 'T array -> 'T list
Evaluates to [ 1; 2; 5 ] .
|
||||||||||
|
Views the given array as a sequence.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val toSeq: array: 'T array -> 'T seq
Evaluates to seq { 1; 2; 5 } .
|
||||||||||
|
Returns the transpose of the given sequence of arrays.
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|]|] .
|
||||||||||
|
Returns at most N elements in a new 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 [| |] .
|
||||||||||
|
Returns the only element of the array or
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 type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val tryExactlyOne: array: 'T array -> 'T option
Evaluates to None
|
||||||||||
|
Returns the first element for which the given function returns True. Return None if no such element exists.
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
|
||||||||||
|
Returns the last element for which the given function returns True. Return None if no such element exists.
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
|
||||||||||
|
Returns the index of the first element in the array that satisfies the given predicate.
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
|
||||||||||
|
Returns the index of the last element in the array that satisfies the given predicate.
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
|
||||||||||
|
Returns the first element of the array, or
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 type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val tryHead: array: 'T array -> 'T option
Evaluates to None
|
||||||||||
|
Tries to find the nth element in the array.
Returns
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 .
|
||||||||||
|
Returns the last element of the array.
Return
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
|
||||||||||
|
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 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 array
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
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 |]
|
||||||||||
|
Splits an array of pairs into 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"|] .
|
||||||||||
|
Splits an array of triples into 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"|] .
|
||||||||||
|
Return a new array with the item at a given index set to the new value.
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 |] .
|
||||||||||
|
Returns a new array containing only the elements of the array 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 |]
|
||||||||||
|
Returns an array of sliding windows containing elements drawn from the input array. Each window is returned as a fresh 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|]|]
|
||||||||||
|
Creates an array where the entries are initially the default value Unchecked.defaultof<'T>.
Example
val arr: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val zeroCreate: count: int -> 'T array
Evaluates to [| 0; 0; 0; 0 |]
|
||||||||||
|
Combines the two arrays into an array of pairs. The two arrays must have equal lengths, otherwise an
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") |] .
|
||||||||||
|
Combines three arrays into an array of pairs. The three arrays must have equal lengths, otherwise an
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")|] .
|