Array.allPairs array1 array2
Full Usage:
Array.allPairs array1 array2
Parameters:
array1
:
'T1 array
-
The first input array.
array2
:
'T2 array
-
The second input array.
Returns:
('T1 * 'T2) array
The resulting array of pairs.
Type parameters:
'T1, 'T2
|
Returns a new array that contains all pairings of elements from the first and second arrays.
This is an O(n*m) operation, where n and m are the lengths of the arrays.
-
array1
:
'T1 array
-
The first input array.
-
array2
:
'T2 array
-
The second input array.
-
Returns:
('T1 * 'T2) array
-
The resulting array of pairs.
Example
([| 1; 2 |], [| 3; 4 |]) ||> Array.allPairs
module Array from Microsoft.FSharp.Collections
val allPairs: array1: 'T1 array -> array2: 'T2 array -> ('T1 * 'T2) array
Evaluates to
[| (1, 3); (1, 4); (2, 3); (2, 4) |]
|
Array.append array1 array2
Full Usage:
Array.append array1 array2
Parameters:
array1
:
'T array
-
The first input array.
array2
:
'T array
-
The second input array.
Returns:
'T array
The resulting array.
Type parameters:
'T
|
Builds a new array that contains the elements of the first array followed by the elements of the second array.
This is an O(n+m) operation, where n and m are the lengths of the arrays.
-
array1
:
'T array
-
The first input array.
-
array2
:
'T array
-
The second input array.
-
Returns:
'T array
-
The resulting array.
Example
Array.append [| 1; 2 |] [| 3; 4 |]
module Array from Microsoft.FSharp.Collections
val append: array1: 'T array -> array2: 'T array -> 'T array
Evaluates to [| 1; 2; 3; 4 |].
|
Array.average array
Full Usage:
Array.average array
Parameters:
array
:
^T array
-
The input array.
Returns:
^T
The average of the elements in the array.
Modifiers:
inline
Type parameters:
^T (requires (static member op_Addition : ^T * ^T -> ^T) and (static member DivideByInt : ^T * Microsoft.FSharp.Core.int -> ^T) and (static member get_Zero : -> ^T))
|
Returns the average of the elements in the array.
This is an O(n) operation, where n is the length of the array.
-
array
:
^T array
-
The input array.
-
Returns:
^T
-
The average of the elements in the array.
Example
[| 1.0; 2.0; 6.0 |] |> Array.average
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
|
Array.averageBy projection array
Full Usage:
Array.averageBy projection array
Parameters:
projection
:
'T -> ^U
-
The function to transform the array elements before averaging.
array
:
'T array
-
The input array.
Returns:
^U
The computed average.
Modifiers:
inline
Type parameters:
'T, ^U (requires (static member op_Addition : ^U * ^U -> ^U) and (static member DivideByInt : ^U * Microsoft.FSharp.Core.int -> ^U) and (static member get_Zero : -> ^U))
|
Returns the average of the elements generated by applying the function to each element of the array.
This is an O(n) operation, where n is the length of the array.
-
projection
:
'T -> ^U
-
The function to transform the array elements before averaging.
-
array
:
'T array
-
The input array.
-
Returns:
^U
-
The computed average.
Example
type Foo = { Bar: float }
let input = [| {Bar = 2.0}; {Bar = 4.0} |]
input |> Array.averageBy (fun foo -> foo.Bar)
type Foo = { Bar: float }
Multiple items val float: value: 'T -> float (requires member op_Explicit)
-------------------- type float = System.Double
-------------------- type float<'Measure> = float
val input: Foo array
module Array from Microsoft.FSharp.Collections
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 }
let input : Foo array = [| |]
input |> Array.averageBy (fun foo -> foo.Bar)
type Foo = { Bar: float }
Multiple items val float: value: 'T -> float (requires member op_Explicit)
-------------------- type float = System.Double
-------------------- type float<'Measure> = float
val input: Foo array
type 'T array = 'T array
module Array from Microsoft.FSharp.Collections
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
|
Array.blit source sourceIndex target targetIndex count
Full Usage:
Array.blit source sourceIndex target targetIndex count
Parameters:
source
:
'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.
let source = [| 12; 13; 14 |]
let target = [| 0; 1; 2; 3; 4; 5 |]
target[3..4] <- source[1..2]
val source: int array
val target: int array
This is an O(count) operation.
-
source
:
'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.
|
ArgumentNullException
|
Thrown when either of the input arrays is null.
|
|
ArgumentException
|
Thrown when any of sourceIndex, targetIndex or count are negative,
or when there aren't enough elements in source or target.
|
Example
let source = [| 12; 13; 14 |]
let target = [| 0; 1; 2; 3; 4; 5 |]
Array.blit source 1 target 3 2
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 |].
|
Array.choose chooser array
Full Usage:
Array.choose chooser array
Parameters:
chooser
:
'T -> 'U option
-
The function to generate options from the elements.
array
:
'T array
-
The input array.
Returns:
'U array
The array of results.
Type parameters:
'T, 'U
|
Applies the given function to each element of the array. Returns
the array comprised of the results x for each element where
the function returns Some(x)
This is an O(n) operation, where n is the length of the array.
-
chooser
:
'T -> 'U option
-
The function to generate options from the elements.
-
array
:
'T array
-
The input array.
-
Returns:
'U array
-
The array of results.
Example
let input = [| Some 1; None; Some 2 |]
input |> Array.choose id
val input: int option array
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
module Array from Microsoft.FSharp.Collections
val choose: chooser: ('T -> 'U option) -> array: 'T array -> 'U array
val id: x: 'T -> 'T
Evaluates to [| 1; 2 |]
Example
let input = [| 1; 2; 3 |]
input |> Array.choose (fun n -> if n % 2 = 0 then Some n else None)
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 chunkSize.
This is an O(n) operation, where n is the length of the array.
-
chunkSize
:
int
-
The maximum size of each chunk.
-
array
:
'T array
-
The input array.
-
Returns:
'T array array
-
The array divided into chunks.
Example
let input = [| 1; 2; 3 |]
input |> Array.chunkBySize 2
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
let input = [| 1; 2; 3 |]
input |> Array.chunkBySize -2
val input: int array
module Array from Microsoft.FSharp.Collections
val chunkBySize: chunkSize: int -> array: 'T array -> 'T array array
Throws ArgumentException
|
Array.collect mapping array
Full Usage:
Array.collect mapping array
Parameters:
mapping
:
'T -> 'U array
-
The function to create sub-arrays from the input array elements.
array
:
'T array
-
The input array.
Returns:
'U array
The concatenation of the sub-arrays.
Type parameters:
'T, 'U
|
For each element of the array, applies the given function. Concatenates all the results and return the combined array.
This is an O(n) operation, where n is the total output length.
-
mapping
:
'T -> 'U array
-
The function to create sub-arrays from the input array elements.
-
array
:
'T array
-
The input array.
-
Returns:
'U array
-
The concatenation of the sub-arrays.
Example
type Foo = { Bar: int array }
let input = [| {Bar = [| 1; 2 |]}; {Bar = [| 3; 4 |]} |]
input |> Array.collect (fun foo -> foo.Bar)
type Foo = { Bar: int array }
Multiple items val int: value: 'T -> int (requires member op_Explicit)
-------------------- type int = int32
-------------------- type int<'Measure> = int
type 'T array = 'T array
val input: Foo array
module Array from Microsoft.FSharp.Collections
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
let input = [[1; 2]; [3; 4]]
input |> Array.collect id
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 |]
|
Array.compareWith comparer array1 array2
Full Usage:
Array.compareWith comparer array1 array2
Parameters:
comparer
:
'T -> 'T -> int
-
A function that takes an element from each array and returns an int.
If it evaluates to a non-zero value iteration is stopped and that value is returned.
array1
:
'T 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.
This is an O(min(n,m)) operation, where n and m are the lengths of the arrays.
-
comparer
:
'T -> 'T -> int
-
A function that takes an element from each array and returns an int.
If it evaluates to a non-zero value iteration is stopped and that value is returned.
-
array1
:
'T 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.
Example
let closerToNextDozen a b =
(a % 12).CompareTo(b % 12)
let input1 = [| 1; 10 |]
let input2 = [| 1; 10 |]
(input1, input2) ||> Array.compareWith closerToNextDozen
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
let closerToNextDozen a b =
(a % 12).CompareTo(b % 12)
let input1 = [| 1; 5 |]
let input2 = [| 1; 8 |]
(input1, input2) ||> Array.compareWith closerToNextDozen
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
let closerToNextDozen a b =
(a % 12).CompareTo(b % 12)
let input1 = [| 1; 11 |]
let input2 = [| 1; 13 |]
(input1, input2) ||> Array.compareWith closerToNextDozen
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
let closerToNextDozen a b =
(a % 12).CompareTo(b % 12)
let input1 = [| 1; 2 |]
let input2 = [| 1 |]
(input1, input2) ||> Array.compareWith closerToNextDozen
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
let closerToNextDozen a b =
(a % 12).CompareTo(b % 12)
let input1 = [| 1 |]
let input2 = [| 1; 2 |]
(input1, input2) ||> Array.compareWith closerToNextDozen
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
|
Array.concat arrays
Full Usage:
Array.concat arrays
Parameters:
arrays
:
'T array seq
-
The input sequence of arrays.
Returns:
'T array
The concatenation of the sequence of input arrays.
Type parameters:
'T
|
Builds a new array that contains the elements of each of the given sequence of arrays.
This is an O(n) operation, where n is the total number of elements across all arrays.
-
arrays
:
'T array seq
-
The input sequence of arrays.
-
Returns:
'T array
-
The concatenation of the sequence of input arrays.
Example
let inputs = [ [| 1; 2 |]; [| 3 |]; [| 4; 5 |] ]
inputs |> Array.concat
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 |]
|
Array.contains value array
Full Usage:
Array.contains value array
Parameters:
value
:
'T
-
The value to locate in the input array.
array
:
'T array
-
The input array.
Returns:
bool
True if the input array contains the specified element; false otherwise.
Modifiers:
inline
Type parameters:
'T (requires equality)
|
Tests if the array contains the specified element.
This is an O(n) operation, where n is the length of the array.
-
value
:
'T
-
The value to locate in the input array.
-
array
:
'T array
-
The input array.
-
Returns:
bool
-
True if the input array contains the specified element; false otherwise.
Example
[| 1; 2 |] |> Array.contains 2 // evaluates to true
[| 1; 2 |] |> Array.contains 5 // evaluates to false
module Array from Microsoft.FSharp.Collections
val contains: value: 'T -> array: 'T array -> bool (requires equality)
|
Array.copy array
Full Usage:
Array.copy array
Parameters:
array
:
'T array
-
The input array.
Returns:
'T array
A copy of the input array. Nonempty results are new arrays.
Empty results can share an empty array, including the input array itself.
Type parameters:
'T
|
Returns an array that contains the elements of the given array.
This is an O(n) operation, where n is the length of the array.
-
array
:
'T array
-
The input array.
-
Returns:
'T array
-
A copy of the input array. Nonempty results are new arrays.
Empty results can share an empty array, including the input array itself.
Example
let source = [| 12; 13; 14 |]
Array.copy source
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 |].
|
Array.countBy projection array
Full Usage:
Array.countBy projection array
Parameters:
projection
:
'T -> 'Key
-
A function transforming each item of the input array into a key to be
compared against the others.
array
:
'T array
-
The input array.
Returns:
('Key * int) array
The result array.
Type parameters:
'T, 'Key (requires equality)
|
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.
This is an O(n) operation, where n is the length of the array.
-
projection
:
'T -> 'Key
-
A function transforming each item of the input array into a key to be
compared against the others.
-
array
:
'T array
-
The input array.
-
Returns:
('Key * int) array
-
The result array.
Example
type Foo = { Bar: string }
let inputs = [| {Bar = "a"}; {Bar = "b"}; {Bar = "a"} |]
inputs |> Array.countBy (fun foo -> foo.Bar)
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) |]
|
Array.create count value
Full Usage:
Array.create count value
Parameters:
count
:
int
-
The length of the array to create.
value
:
'T
-
The value for the elements.
Returns:
'T array
The created array.
Type parameters:
'T
|
Creates an array whose elements are all initially the given value.
This is an O(n) operation, where n is the count.
-
count
:
int
-
The length of the array to create.
-
value
:
'T
-
The value for the elements.
-
Returns:
'T array
-
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
let cell = ref "a"
let array = Array.create 2 cell
cell.Value <- "b"
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.
|
Array.distinct array
Full Usage:
Array.distinct array
Parameters:
array
:
'T array
-
The input array.
Returns:
'T array
The result array.
Type parameters:
'T (requires equality)
|
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.
This is an O(n) operation, where n is the length of the array.
-
array
:
'T array
-
The input array.
-
Returns:
'T array
-
The result array.
Example
let input = [| 1; 1; 2; 3 |]
input |> Array.distinct
val input: int array
module Array from Microsoft.FSharp.Collections
val distinct: array: 'T array -> 'T array (requires equality)
Evaluates to [| 1; 2; 3 |]
|
Array.distinctBy projection array
Full Usage:
Array.distinctBy projection array
Parameters:
projection
:
'T -> 'Key
-
A function transforming the array items into comparable keys.
array
:
'T array
-
The input array.
Returns:
'T array
The result array.
Type parameters:
'T, 'Key (requires equality)
|
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.
This is an O(n) operation, where n is the length of the array.
-
projection
:
'T -> 'Key
-
A function transforming the array items into comparable keys.
-
array
:
'T array
-
The input array.
-
Returns:
'T array
-
The result array.
Example
let inputs = [| {Bar = 1 };{Bar = 1}; {Bar = 2}; {Bar = 3} |]
inputs |> Array.distinctBy (fun foo -> foo.Bar)
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 } |]
|
Array.empty
Full Usage:
Array.empty
Returns:
'T array
The empty array.
Type parameters:
'T
|
Returns an empty array of the given type.
This is an O(1) operation.
-
Returns:
'T array
-
The empty array.
Example
Array.empty // Evaluates to [| |]
module Array from Microsoft.FSharp.Collections
val empty<'T> : 'T array
|
Array.exactlyOne array
Full Usage:
Array.exactlyOne array
Parameters:
array
:
'T array
-
The input array.
Returns:
'T
The only element of the array.
Type parameters:
'T
|
Returns the only element of the array.
This is an O(1) operation.
-
array
:
'T array
-
The input array.
-
Returns:
'T
-
The only element of the array.
Example
let inputs = [| "banana" |]
inputs |> Array.exactlyOne
val inputs: string array
module Array from Microsoft.FSharp.Collections
val exactlyOne: array: 'T array -> 'T
Evaluates to banana
Example
let inputs = [| "pear"; "banana" |]
inputs |> Array.exactlyOne
val inputs: string array
module Array from Microsoft.FSharp.Collections
val exactlyOne: array: 'T array -> 'T
Throws ArgumentException
Example
let inputs: int array = [| |]
inputs |> Array.exactlyOne
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
|
Array.except itemsToExclude array
Full Usage:
Array.except itemsToExclude array
Parameters:
itemsToExclude
:
'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.
Type parameters:
'T (requires equality)
|
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.
This is an O(n+m) operation using hash-based exclusion.
-
itemsToExclude
:
'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.
Example
let original = [| 1; 2; 3; 4; 5 |]
let itemsToExclude = [| 1; 3; 5 |]
original |> Array.except itemsToExclude
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 |]
|
Array.exists predicate array
Full Usage:
Array.exists predicate array
Parameters:
predicate
:
'T -> bool
-
The function to test the input elements.
array
:
'T array
-
The input array.
Returns:
bool
True if any result from predicate is true.
Modifiers:
inline
Type parameters:
'T
|
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. This is an O(n) operation in the worst case, where n is the length of the array.
-
predicate
:
'T -> bool
-
The function to test the input elements.
-
array
:
'T array
-
The input array.
-
Returns:
bool
-
True if any result from predicate is true.
Example
let input = [| 1; 2; 3; 4; 5 |]
input |> Array.exists (fun elm -> elm % 4 = 0)
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
let input = [| 1; 2; 3; 4; 5 |]
input |> Array.exists (fun elm -> elm % 6 = 0)
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
|
Array.exists2 predicate array1 array2
Full Usage:
Array.exists2 predicate array1 array2
Parameters:
predicate
:
'T1 -> 'T2 -> bool
-
The function to test the input elements.
array1
:
'T1 array
-
The first input array.
array2
:
'T2 array
-
The second input array.
Returns:
bool
True if any result from predicate is true.
Modifiers:
inline
Type parameters:
'T1, 'T2
|
Tests if any pair of corresponding elements of the arrays satisfies the given predicate.
The predicate is applied to matching elements in the two collections up to the lesser of the
two lengths of the collections. If any application returns true then the overall result is
true and no further elements are tested. Otherwise, if one collections is longer
than the other then the ArgumentException exception is raised.
Otherwise, false is returned. This is an O(n) operation in the worst case, where n is the length of the arrays.
-
predicate
:
'T1 -> 'T2 -> bool
-
The function to test the input elements.
-
array1
:
'T1 array
-
The first input array.
-
array2
:
'T2 array
-
The second input array.
-
Returns:
bool
-
True if any result from predicate is true.
Example
let inputs1 = [| 1; 2 |]
let inputs2 = [| 1; 3 |]
(inputs1, inputs2) ||> Array.exists2 (fun a b -> a > b)
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
let inputs1 = [| 1; 4 |]
let inputs2 = [| 1; 3 |]
(inputs1, inputs2) ||> Array.exists2 (fun a b -> a > b)
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
|
Array.fill target targetIndex count value
Full Usage:
Array.fill target targetIndex count value
Parameters:
target
:
'T array
-
The target array.
targetIndex
:
int
-
The index of the first element to set.
count
:
int
-
The number of elements to set.
value
:
'T
-
The value to set.
Type parameters:
'T
|
Fills a range of elements of the array with the given value.
This is an O(count) operation.
-
target
:
'T array
-
The target array.
-
targetIndex
:
int
-
The index of the first element to set.
-
count
:
int
-
The number of elements to set.
-
value
:
'T
-
The value to set.
Example
let target = [| 0; 1; 2; 3; 4; 5 |]
Array.fill target 3 2 100
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 |].
|
Array.filter predicate array
Full Usage:
Array.filter predicate array
Parameters:
predicate
:
'T -> bool
-
The function to test the input elements.
array
:
'T array
-
The input array.
Returns:
'T array
An array containing the elements for which the given predicate returns true.
Type parameters:
'T
|
Returns a new collection containing only the elements of the collection
for which the given predicate returns "true".
This is an O(n) operation, where n is the length of the array.
-
predicate
:
'T -> bool
-
The function to test the input elements.
-
array
:
'T array
-
The input array.
-
Returns:
'T array
-
An array containing the elements for which the given predicate returns true.
Example
let inputs = [| 1; 2; 3; 4 |]
inputs |> Array.filter (fun elm -> elm % 2 = 0)
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 |]
|
Array.find predicate array
Full Usage:
Array.find predicate array
Parameters:
predicate
:
'T -> bool
-
The function to test the input elements.
array
:
'T array
-
The input array.
Returns:
'T
The first element for which predicate returns true.
Modifiers:
inline
Type parameters:
'T
|
Returns the first element for which the given function returns 'true'.
Raise KeyNotFoundException if no such element exists.
This is an O(n) operation in the worst case, where n is the length of the array.
-
predicate
:
'T -> bool
-
The function to test the input elements.
-
array
:
'T array
-
The input array.
-
Returns:
'T
-
The first element for which predicate returns true.
Example
let inputs = [| 1; 2; 3 |]
inputs |> Array.find (fun elm -> elm % 2 = 0)
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
let inputs = [| 1; 2; 3 |]
inputs |> Array.find (fun elm -> elm % 6 = 0)
val inputs: int array
module Array from Microsoft.FSharp.Collections
val find: predicate: ('T -> bool) -> array: 'T array -> 'T
val elm: int
Throws KeyNotFoundException
|
Array.findBack predicate array
Full Usage:
Array.findBack predicate array
Parameters:
predicate
:
'T -> bool
-
The function to test the input elements.
array
:
'T array
-
The input array.
Returns:
'T
The last element for which predicate returns true.
Modifiers:
inline
Type parameters:
'T
|
Returns the last element for which the given function returns 'true'.
Raise KeyNotFoundException if no such element exists.
This is an O(n) operation in the worst case, where n is the length of the array.
-
predicate
:
'T -> bool
-
The function to test the input elements.
-
array
:
'T array
-
The input array.
-
Returns:
'T
-
The last element for which predicate returns true.
Example
let inputs = [| 2; 3; 4 |]
inputs |> Array.findBack (fun elm -> elm % 2 = 0)
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
let inputs = [| 2; 3; 4 |]
inputs |> Array.findBack (fun elm -> elm % 6 = 0)
val inputs: int array
module Array from Microsoft.FSharp.Collections
val findBack: predicate: ('T -> bool) -> array: 'T array -> 'T
val elm: int
Throws KeyNotFoundException
|
Array.findIndex predicate array
Full Usage:
Array.findIndex predicate array
Parameters:
predicate
:
'T -> bool
-
The function to test the input elements.
array
:
'T array
-
The input array.
Returns:
int
The index of the first element in the array that satisfies the given predicate.
Modifiers:
inline
Type parameters:
'T
|
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.
This is an O(n) operation in the worst case, where n is the length of the array.
-
predicate
:
'T -> bool
-
The function to test the input elements.
-
array
:
'T array
-
The input array.
-
Returns:
int
-
The index of the first element in the array that satisfies the given predicate.
Example
let inputs = [| 1; 2; 3; 4; 5 |]
inputs |> Array.findIndex (fun elm -> elm % 2 = 0)
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
let inputs = [| 1; 2; 3; 4; 5 |]
inputs |> Array.findIndex (fun elm -> elm % 6 = 0)
val inputs: int array
module Array from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> array: 'T array -> int
val elm: int
Throws KeyNotFoundException
|
Array.findIndexBack predicate array
Full Usage:
Array.findIndexBack predicate array
Parameters:
predicate
:
'T -> bool
-
The function to test the input elements.
array
:
'T array
-
The input array.
Returns:
int
The index of the last element in the array that satisfies the given predicate.
Modifiers:
inline
Type parameters:
'T
|
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.
This is an O(n) operation in the worst case, where n is the length of the array.
-
predicate
:
'T -> bool
-
The function to test the input elements.
-
array
:
'T array
-
The input array.
-
Returns:
int
-
The index of the last element in the array that satisfies the given predicate.
Example
let inputs = [| 1; 2; 3; 4; 5 |]
inputs |> Array.findIndex (fun elm -> elm % 2 = 0)
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
let inputs = [| 1; 2; 3; 4; 5 |]
inputs |> Array.findIndex (fun elm -> elm % 6 = 0)
val inputs: int array
module Array from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> array: 'T array -> int
val elm: int
Throws KeyNotFoundException
|
Array.fold folder state array
Full Usage:
Array.fold folder state array
Parameters:
folder
:
'State -> 'T -> 'State
-
The function to update the state given the input elements.
state
:
'State
-
The initial state.
array
:
'T array
-
The input array.
Returns:
'State
The final state.
Modifiers:
inline
Type parameters:
'T, 'State
|
Applies a function to each element of the collection, threading an accumulator argument
through the computation. If the input function is f and the elements are i0...iN then computes
f (... (f s i0)...) iN
This is an O(n) operation, where n is the length of the array.
-
folder
:
'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.
Example
type Charge =
| In of int
| Out of int
let inputs = [| In 1; Out 2; In 3 |]
(0, inputs) ||> Array.fold (fun acc charge ->
match charge with
| In i -> acc + i
| Out o -> acc - o)
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
|
Array.fold2 folder state array1 array2
Full Usage:
Array.fold2 folder state array1 array2
Parameters:
folder
:
'State -> 'T1 -> 'T2 -> 'State
-
The function to update the state given the input elements.
state
:
'State
-
The initial state.
array1
:
'T1 array
-
The first input array.
array2
:
'T2 array
-
The second input array.
Returns:
'State
The final state.
Modifiers:
inline
Type parameters:
'T1, 'T2, 'State
|
Applies a function to pairs of elements drawn from the two collections,
left-to-right, threading an accumulator argument
through the computation. The two input
arrays must have the same lengths, otherwise an ArgumentException is
raised.
This is an O(n) operation, where n is the length of the arrays.
-
folder
:
'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.
Example
type CoinToss = Head | Tails
let data1 = [| Tails; Head; Tails |]
let data2 = [| Tails; Head; Head |]
(0, data1, data2) |||> Array.fold2 (fun acc a b ->
match (a, b) with
| Head, Head -> acc + 1
| Tails, Tails -> acc + 1
| _ -> acc - 1)
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
|
Array.foldBack folder array state
Full Usage:
Array.foldBack folder array state
Parameters:
folder
:
'T -> 'State -> 'State
-
The function to update the state given the input elements.
array
:
'T 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.
Modifiers:
inline
Type parameters:
'T, 'State
|
Applies a function to each element of the array, starting from the end, threading an accumulator argument
through the computation. If the input function is f and the elements are i0...iN then computes
f i0 (...(f iN s))
This is an O(n) operation, where n is the length of the array.
-
folder
:
'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.
Example
type Count =
{ Positive: int
Negative: int
Text: string }
let sequence = [| 1; 0; -1; -2; 3 |]
let initialState = {Positive = 0; Negative = 0; Text = "" }
(sequence, initialState) ||> Array.foldBack (fun a acc ->
let text = acc.Text + " " + string a
if a >= 0 then
{ acc with
Positive = acc.Positive + 1
Text = text }
else
{ acc with
Negative = acc.Negative + 1
Text = text })
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
{ Positive = 2
Negative = 3
Text = " 3 -2 -1 0 1" }
|
Array.foldBack2 folder array1 array2 state
Full Usage:
Array.foldBack2 folder array1 array2 state
Parameters:
folder
:
'T1 -> 'T2 -> 'State -> 'State
-
The function to update the state given the input elements.
array1
:
'T1 array
-
The first input array.
array2
:
'T2 array
-
The second input array.
state
:
'State
-
The initial state.
Returns:
'State
The final state.
Modifiers:
inline
Type parameters:
'T1, 'T2, 'State
|
Apply a function to pairs of elements drawn from the two collections, right-to-left,
threading an accumulator argument through the computation. The two input
arrays must have the same lengths, otherwise an ArgumentException is
raised.
This is an O(n) operation, where n is the length of the arrays.
-
folder
:
'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.
Example
Count the positives, negatives and accumulate some text from back to front:
type Count =
{ Positive: int
Negative: int
Text: string }
let inputs1 = [| -1; -2; -3 |]
let inputs2 = [| 3; 2; 1 |]
let initialState = {Positive = 0; Negative = 0; Text = ""}
(inputs1, inputs2, initialState) |||> Array.foldBack2 (fun a b acc ->
let text = acc.Text + "(" + string a + "," + string b + ") "
if a + b >= 0 then
{ acc with
Positive = acc.Positive + 1
Text = text }
else
{ acc with
Negative = acc.Negative + 1
Text = text }
)
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
module Array from Microsoft.FSharp.Collections
val foldBack2: folder: ('T1 -> 'T2 -> 'State -> 'State) -> array1: 'T1 array -> array2: 'T2 array -> state: 'State -> 'State
Evaluates to
{ Positive = 2
Negative = 1
Text = "(-3,1) (-2,2) (-1,3) " }
|
Array.forall predicate array
Full Usage:
Array.forall predicate array
Parameters:
predicate
:
'T -> bool
-
The function to test the input elements.
array
:
'T array
-
The input array.
Returns:
bool
True if all of the array elements satisfy the predicate.
Modifiers:
inline
Type parameters:
'T
|
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. This is an O(n) operation in the worst case, where n is the length of the array.
-
predicate
:
'T -> bool
-
The function to test the input elements.
-
array
:
'T array
-
The input array.
-
Returns:
bool
-
True if all of the array elements satisfy the predicate.
Example
let isEven a = a % 2 = 0
[2; 42] |> Array.forall isEven // evaluates to true
[1; 2] |> Array.forall isEven // evaluates to false
val isEven: a: int -> bool
val a: int
module Array from Microsoft.FSharp.Collections
val forall: predicate: ('T -> bool) -> array: 'T array -> bool
|
Array.forall2 predicate array1 array2
Full Usage:
Array.forall2 predicate array1 array2
Parameters:
predicate
:
'T1 -> 'T2 -> bool
-
The function to test the input elements.
array1
:
'T1 array
-
The first input array.
array2
:
'T2 array
-
The second input array.
Returns:
bool
True if all of the array elements satisfy the predicate.
Modifiers:
inline
Type parameters:
'T1, 'T2
|
Tests if all corresponding elements of the array satisfy the given predicate pairwise.
The predicate is applied to matching elements in the two collections up to the lesser of the
two lengths of the collections. If any application returns false then the overall result is
false and no further elements are tested. Otherwise, if one collection is longer
than the other then the ArgumentException exception is raised.
Otherwise, true is returned. This is an O(n) operation in the worst case, where n is the length of the arrays.
-
predicate
:
'T1 -> 'T2 -> bool
-
The function to test the input elements.
-
array1
:
'T1 array
-
The first input array.
-
array2
:
'T2 array
-
The second input array.
-
Returns:
bool
-
True if all of the array elements satisfy the predicate.
Example
let inputs1 = [| 1; 2; 3 |]
let inputs2 = [| 1; 2; 3 |]
(inputs1, inputs2) ||> Array.forall2 (=)
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
let items1 = [| 2017; 1; 1 |]
let items2 = [| 2019; 19; 8 |]
(items1, items2) ||> Array.forall2 (=)
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
let items1 = [| 1; 2; 3 |]
let items2 = [| 1; 2 |]
(items1, items2) ||> Array.forall2 (=)
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.
|
Array.get array index
Full Usage:
Array.get array index
Parameters:
array
:
'T array
-
The input array.
index
:
int
-
The input index.
Returns:
'T
The value of the array at the given index.
Type parameters:
'T
|
Gets an element from an array.
Normally the syntax array[index] is preferred. This is an O(1) operation.
-
array
:
'T array
-
The input array.
-
index
:
int
-
The input index.
-
Returns:
'T
-
The value of the array at the given index.
Example
let inputs = [| "a"; "b"; "c" |]
Array.get inputs 1
val inputs: string array
module Array from Microsoft.FSharp.Collections
val get: array: 'T array -> index: int -> 'T
Evaluates to "b"
Example
let inputs = [| "a"; "b"; "c" |]
Array.get inputs 4
val inputs: string array
module Array from Microsoft.FSharp.Collections
val get: array: 'T array -> index: int -> 'T
Throws IndexOutOfRangeException
|
Array.groupBy projection array
Full Usage:
Array.groupBy projection array
Parameters:
projection
:
'T -> 'Key
-
A function that transforms an element of the array into a comparable key.
array
:
'T array
-
The input array.
Returns:
('Key * 'T array) array
The result array.
Type parameters:
'T, 'Key (requires equality)
|
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.
This is an O(n) operation, where n is the length of the array.
-
projection
:
'T -> 'Key
-
A function that transforms an element of the array into a comparable key.
-
array
:
'T array
-
The input array.
-
Returns:
('Key * 'T array) array
-
The result array.
Example
let inputs = [| 1; 2; 3; 4; 5 |]
inputs |> Array.groupBy (fun n -> n % 2)
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 |]) |]
|
Array.head array
Full Usage:
Array.head array
Parameters:
array
:
'T array
-
The input array.
Returns:
'T
The first element of the array.
Type parameters:
'T
|
Returns the first element of the array.
This is an O(1) operation.
-
array
:
'T array
-
The input array.
-
Returns:
'T
-
The first element of the array.
Example
let inputs = [| "banana"; "pear" |]
inputs |> Array.head
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
|
Array.indexed array
Full Usage:
Array.indexed array
Parameters:
array
:
'T array
-
The input array.
Returns:
(int * 'T) array
The array of indexed elements.
Type parameters:
'T
|
Builds a new array whose elements are the corresponding elements of the input array
paired with the integer index (from 0) of each element.
This is an O(n) operation, where n is the length of the array.
-
array
:
'T array
-
The input array.
-
Returns:
(int * 'T) array
-
The array of indexed elements.
Example
let inputs = [| "a"; "b"; "c" |]
inputs |> Array.indexed
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") |]
|
Array.init count initializer
Full Usage:
Array.init count initializer
Parameters:
count
:
int
-
The number of elements to initialize.
initializer
:
int -> 'T
-
The function to generate the initial values for each index.
Returns:
'T array
The created array.
Modifiers:
inline
Type parameters:
'T
|
Creates an array given the dimension and a generator function to compute the elements.
This is an O(n) operation, where n is the count.
-
count
:
int
-
The number of elements to initialize.
-
initializer
:
int -> 'T
-
The function to generate the initial values for each index.
-
Returns:
'T array
-
The created array.
Example
Array.init 4 (fun v -> v + 5)
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
Array.init -5 (fun v -> v + 5)
module Array from Microsoft.FSharp.Collections
val init: count: int -> initializer: (int -> 'T) -> 'T array
val v: int
Throws ArgumentException
|
Array.insertAt index value source
Full Usage:
Array.insertAt index value source
Parameters:
index
:
int
-
The index where the item should be inserted.
value
:
'T
-
The value to insert.
source
:
'T array
-
The input array.
Returns:
'T array
The result array.
Type parameters:
'T
|
Return a new array with a new item inserted before the given index.
This is an O(n) operation, where n is the length of the array.
-
index
:
int
-
The index where the item should be inserted.
-
value
:
'T
-
The value to insert.
-
source
:
'T array
-
The input array.
-
Returns:
'T array
-
The result array.
Example
let inputs = [| 0; 1; 2 |]
inputs |> Array.insertAt 1 9
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 |].
|
Array.insertManyAt index values source
Full Usage:
Array.insertManyAt index values source
Parameters:
index
:
int
-
The index where the items should be inserted.
values
:
'T seq
-
The values to insert.
source
:
'T array
-
The input array.
Returns:
'T array
A new array, even if values is empty, unless both source and values are empty.
In that case, the result can be a shared empty array, including source itself.
Type parameters:
'T
|
Returns an array with new items inserted before the given index.
This is an O(n+m) operation, where n is the length of the array and m is the number of elements to insert.
-
index
:
int
-
The index where the items should be inserted.
-
values
:
'T seq
-
The values to insert.
-
source
:
'T array
-
The input array.
-
Returns:
'T array
-
A new array, even if values is empty, unless both source and values are empty.
In that case, the result can be a shared empty array, including source itself.
Example
let inputs = [| 0; 1; 2 |]
inputs |> Array.insertManyAt 1 [8; 9]
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 |].
|
Array.isEmpty array
Full Usage:
Array.isEmpty array
Parameters:
array
:
'T array
-
The input array.
Returns:
bool
True if the array is empty.
Type parameters:
'T
|
Returns true if the given array is empty, otherwise false.
This is an O(1) operation.
-
array
:
'T array
-
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
[| "pear"; "banana" |] |> Array.isEmpty
module Array from Microsoft.FSharp.Collections
val isEmpty: array: 'T array -> bool
Evaluates to false
|
Array.item index array
Full Usage:
Array.item index array
Parameters:
index
:
int
-
The input index.
array
:
'T array
-
The input array.
Returns:
'T
The value of the array at the given index.
Type parameters:
'T
|
Gets an element from an array.
Normally the syntax array[index] is preferred. This is an O(1) operation.
-
index
:
int
-
The input index.
-
array
:
'T array
-
The input array.
-
Returns:
'T
-
The value of the array at the given index.
Example
let inputs = [| "a"; "b"; "c" |]
inputs |> Array.item 1
val inputs: string array
module Array from Microsoft.FSharp.Collections
val item: index: int -> array: 'T array -> 'T
Evaluates to "b"
Example
let inputs = [| "a"; "b"; "c" |]
inputs |> Array.item 4
val inputs: string array
module Array from Microsoft.FSharp.Collections
val item: index: int -> array: 'T array -> 'T
Throws ArgumentException
|
Array.iter action array
Full Usage:
Array.iter action array
Parameters:
action
:
'T -> unit
-
The function to apply.
array
:
'T array
-
The input array.
Modifiers:
inline
Type parameters:
'T
|
Applies the given function to each element of the array.
This is an O(n) operation, where n is the length of the array.
-
action
:
'T -> unit
-
The function to apply.
-
array
:
'T array
-
The input array.
Example
let inputs = [| "a"; "b"; "c" |]
inputs |> Array.iter (printfn "%s")
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.
|
Array.iter2 action array1 array2
Full Usage:
Array.iter2 action array1 array2
Parameters:
action
:
'T1 -> 'T2 -> unit
-
The function to apply.
array1
:
'T1 array
-
The first input array.
array2
:
'T2 array
-
The second input array.
Modifiers:
inline
Type parameters:
'T1, 'T2
|
Applies the given function to pair of elements drawn from matching indices in two arrays. The
two arrays must have the same lengths, otherwise an ArgumentException is
raised.
This is an O(n) operation, where n is the length of the arrays.
-
action
:
'T1 -> 'T2 -> unit
-
The function to apply.
-
array1
:
'T1 array
-
The first input array.
-
array2
:
'T2 array
-
The second input array.
Example
let inputs1 = [| "a"; "b"; "c" |]
let inputs2 = [| 1; 2; 3 |]
(inputs1, inputs2) ||> Array.iter2 (printfn "%s: %i")
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.
|
Array.iteri action array
Full Usage:
Array.iteri action array
Parameters:
action
:
int -> 'T -> unit
-
The function to apply to each index and element.
array
:
'T array
-
The input array.
Modifiers:
inline
Type parameters:
'T
|
Applies the given function to each element of the array. The integer passed to the
function indicates the index of element.
This is an O(n) operation, where n is the length of the array.
-
action
:
int -> 'T -> unit
-
The function to apply to each index and element.
-
array
:
'T array
-
The input array.
Example
let inputs = [| "a"; "b"; "c" |]
inputs |> Array.iteri (fun i v -> printn $"{i}: {v}")
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
Evaluates to unit and prints
in the console.
|
Array.iteri2 action array1 array2
Full Usage:
Array.iteri2 action array1 array2
Parameters:
action
:
int -> 'T1 -> 'T2 -> unit
-
The function to apply to each index and pair of elements.
array1
:
'T1 array
-
The first input array.
array2
:
'T2 array
-
The second input array.
Modifiers:
inline
Type parameters:
'T1, 'T2
|
Applies the given function to pair of elements drawn from matching indices in two arrays,
also passing the index of the elements. The two arrays must have the same lengths,
otherwise an ArgumentException is raised.
This is an O(n) operation, where n is the length of the arrays.
-
action
:
int -> 'T1 -> 'T2 -> unit
-
The function to apply to each index and pair of elements.
-
array1
:
'T1 array
-
The first input array.
-
array2
:
'T2 array
-
The second input array.
Example
let inputs1 = [| "a"; "b"; "c" |]
let inputs2 = [| "banana"; "pear"; "apple" |]
(inputs1, inputs2) ||> Array.iteri2 (fun i s1 s2 -> printfn "Index {i}: {s1} - {s2}")
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
Index 0: a - banana
Index 1: b - pear
Index 2: c - apple
in the console.
|
Array.last array
Full Usage:
Array.last array
Parameters:
array
:
'T array
-
The input array.
Returns:
'T
The last element of the array.
Modifiers:
inline
Type parameters:
'T
|
Returns the last element of the array.
This is an O(1) operation.
-
array
:
'T array
-
The input array.
-
Returns:
'T
-
The last element of the array.
Example
[| "pear"; "banana" |] |> Array.last
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
|
Array.length array
Full Usage:
Array.length array
Parameters:
array
:
'T array
-
The input array.
Returns:
int
The length of the array.
Type parameters:
'T
|
Returns the length of an array. You can also use property arr.Length.
The notation array.Length is preferred. This is an O(1) operation.This is an O(1) operation.
-
array
:
'T array
-
The input array.
-
Returns:
int
-
The length of the array.
Example
let inputs = [| "a"; "b"; "c" |]
inputs |> Array.length
val inputs: string array
module Array from Microsoft.FSharp.Collections
val length: array: 'T array -> int
Evaluates to 3
|
Array.map mapping array
Full Usage:
Array.map mapping array
Parameters:
mapping
:
'T -> 'U
-
The function to transform elements of the array.
array
:
'T array
-
The input array.
Returns:
'U array
The array of transformed elements.
Modifiers:
inline
Type parameters:
'T, 'U
|
Builds a new array whose elements are the results of applying the given function
to each of the elements of the array.
This is an O(n) operation, where n is the length of the array.
-
mapping
:
'T -> 'U
-
The function to transform elements of the array.
-
array
:
'T array
-
The input array.
-
Returns:
'U array
-
The array of transformed elements.
Example
let inputs = [| "a"; "bbb"; "cc" |]
inputs |> Array.map (fun x -> x.Length)
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 |]
|
Array.map2 mapping array1 array2
Full Usage:
Array.map2 mapping array1 array2
Parameters:
mapping
:
'T1 -> 'T2 -> 'U
-
The function to transform the pairs of the input elements.
array1
:
'T1 array
-
The first input array.
array2
:
'T2 array
-
The second input array.
Returns:
'U array
The array of transformed elements.
Type parameters:
'T1, 'T2, 'U
|
Builds a new collection whose elements are the results of applying the given function
to the corresponding elements of the two collections pairwise. The two input
arrays must have the same lengths, otherwise an ArgumentException is
raised.
This is an O(n) operation, where n is the length of the arrays.
-
mapping
:
'T1 -> 'T2 -> '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.
-
Returns:
'U array
-
The array of transformed elements.
Example
let inputs1 = [| "a"; "bad"; "good" |]
let inputs2 = [| 0; 2; 1 |]
(inputs1, inputs2) ||> Array.map2 (fun x y -> x[y])
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' |]
|
Array.map3 mapping array1 array2 array3
Full Usage:
Array.map3 mapping array1 array2 array3
Parameters:
mapping
:
'T1 -> 'T2 -> 'T3 -> 'U
-
The function to transform the pairs of the input elements.
array1
:
'T1 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.
Type parameters:
'T1, 'T2, 'T3, 'U
|
Builds a new collection whose elements are the results of applying the given function
to the corresponding triples from the three collections. The three input
arrays must have the same length, otherwise an ArgumentException is
raised.
This is an O(n) operation, where n is the length of the arrays.
-
mapping
:
'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.
Example
let inputs1 = [| "a"; "t"; "ti" |]
let inputs2 = [| "l"; "h"; "m" |]
let inputs3 = [| "l"; "e"; "e" |]
(inputs1, inputs2, inputs3) |||> Array.map3 (fun x y z -> x + y + z)
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" |]
|
Array.mapFold mapping state array
Full Usage:
Array.mapFold mapping state array
Parameters:
mapping
:
'State -> 'T -> 'Result * 'State
-
The function to transform elements from the input array and accumulate the final value.
state
:
'State
-
The initial state.
array
:
'T array
-
The input array.
Returns:
'Result array * 'State
The array of transformed elements, and the final accumulated value.
Type parameters:
'T, 'State, 'Result
|
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.
This is an O(n) operation, where n is the length of the array.
-
mapping
:
'State -> 'T -> 'Result * 'State
-
The function to transform elements from the input array and accumulate the final value.
-
state
:
'State
-
The initial state.
-
array
:
'T array
-
The input array.
-
Returns:
'Result array * 'State
-
The array of transformed elements, and the final accumulated value.
Example
Accumulate the charges, and double them as well
type Charge =
| In of int
| Out of int
let inputs = [| In 1; Out 2; In 3 |]
let newCharges, balance =
(0, inputs) ||> Array.mapFold (fun acc charge ->
match charge with
| In i -> In (i*2), acc + i
| Out o -> Out (o*2), acc - o)
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.
|
Array.mapFoldBack mapping array state
Full Usage:
Array.mapFoldBack mapping array state
Parameters:
mapping
:
'T -> 'State -> 'Result * 'State
-
The function to transform elements from the input array and accumulate the final value.
array
:
'T array
-
The input array.
state
:
'State
-
The initial state.
Returns:
'Result array * 'State
The array of transformed elements, and the final accumulated value.
Type parameters:
'T, 'State, 'Result
|
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.
This is an O(n) operation, where n is the length of the array.
-
mapping
:
'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.
Example
Accumulate the charges from back to front, and double them as well
type Charge =
| In of int
| Out of int
let inputs = [| In 1; Out 2; In 3 |]
let newCharges, balance =
(inputs, 0) ||> Array.mapFoldBack (fun charge acc ->
match charge with
| In i -> In (i*2), acc + i
| Out o -> Out (o*2), acc - o)
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.
|
Array.mapi mapping array
Full Usage:
Array.mapi mapping array
Parameters:
mapping
:
int -> 'T -> 'U
-
The function to transform elements and their indices.
array
:
'T array
-
The input array.
Returns:
'U array
The array of transformed elements.
Type parameters:
'T, 'U
|
Builds a new array whose elements are the results of applying the given function
to each of the elements of the array. The integer index passed to the
function indicates the index of element being transformed, starting at zero.
This is an O(n) operation, where n is the length of the array.
-
mapping
:
int -> 'T -> 'U
-
The function to transform elements and their indices.
-
array
:
'T array
-
The input array.
-
Returns:
'U array
-
The array of transformed elements.
Example
let inputs = [| 10; 10; 10 |]
inputs |> Array.mapi (fun i x -> i + x)
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 |]
|
Array.mapi2 mapping array1 array2
Full Usage:
Array.mapi2 mapping array1 array2
Parameters:
mapping
:
int -> 'T1 -> 'T2 -> 'U
-
The function to transform pairs of input elements and their indices.
array1
:
'T1 array
-
The first input array.
array2
:
'T2 array
-
The second input array.
Returns:
'U array
The array of transformed elements.
Type parameters:
'T1, 'T2, 'U
|
Builds a new collection whose elements are the results of applying the given function
to the corresponding elements of the two collections pairwise, also passing the index of
the elements. The two input arrays must have the same lengths, otherwise an ArgumentException is
raised.
This is an O(n) operation, where n is the length of the arrays.
-
mapping
:
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.
Example
let inputs1 = [| "a"; "bad"; "good" |]
let inputs2 = [| 0; 2; 1 |]
(inputs1, inputs2) ||> Array.mapi2 (fun i x y -> i, x[y])
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')|]
|
Array.max array
Full Usage:
Array.max array
Parameters:
array
:
'T array
-
The input array.
Returns:
'T
The maximum element.
Modifiers:
inline
Type parameters:
'T (requires comparison)
|
Returns the greatest of all elements of the array, compared via Operators.max on the function result.
Throws ArgumentException for empty arrays. This is an O(n) operation, where n is the length of the array.
-
array
:
'T array
-
The input array.
-
Returns:
'T
-
The maximum element.
Example
let inputs = [| 10; 12; 11 |]
inputs |> Array.max
val inputs: int array
module Array from Microsoft.FSharp.Collections
val max: array: 'T array -> 'T (requires comparison)
Evaluates to 12
Example
let inputs: int array= [| |]
inputs |> Array.max
val inputs: int array
Multiple items val int: value: 'T -> int (requires member op_Explicit)
-------------------- type int = int32
-------------------- type int<'Measure> = int
type 'T array = 'T array
module Array from Microsoft.FSharp.Collections
val max: array: 'T array -> 'T (requires comparison)
Throws System.ArgumentException.
|
Array.maxBy projection array
Full Usage:
Array.maxBy projection array
Parameters:
projection
:
'T -> 'U
-
The function to transform the elements into a type supporting comparison.
array
:
'T array
-
The input array.
Returns:
'T
The maximum element.
Modifiers:
inline
Type parameters:
'T, 'U (requires comparison)
|
Returns the greatest of all elements of the array, compared via Operators.max on the function result.
Returns the first maximal element of the array if there are multiple equal maximum elements.
Throws ArgumentException for empty arrays. This is an O(n) operation, where n is the length of the array.
-
projection
:
'T -> 'U
-
The function to transform the elements into a type supporting comparison.
-
array
:
'T array
-
The input array.
-
Returns:
'T
-
The maximum element.
Example
let inputs = [| "aaa"; "b"; "cccc" |]
inputs |> Array.maxBy (fun s -> s.Length)
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
let inputs: string array= [| |]
inputs |> Array.maxBy (fun s -> s.Length)
val inputs: string array
Multiple items val string: value: 'T -> string
-------------------- type string = System.String
type 'T array = 'T array
module Array from Microsoft.FSharp.Collections
val maxBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Throws System.ArgumentException.
|
Array.min array
Full Usage:
Array.min array
Parameters:
array
:
'T array
-
The input array.
Returns:
'T
The minimum element.
Modifiers:
inline
Type parameters:
'T (requires comparison)
|
Returns the lowest of all elements of the array, compared via Operators.min.
Throws ArgumentException for empty arrays. This is an O(n) operation, where n is the length of the array.
-
array
:
'T array
-
The input array.
-
Returns:
'T
-
The minimum element.
Example
let inputs = [| 10; 12; 11 |]
inputs |> Array.min
val inputs: int array
module Array from Microsoft.FSharp.Collections
val min: array: 'T array -> 'T (requires comparison)
Evaluates to 10
Example
let inputs: int array= [| |]
inputs |> Array.min
val inputs: int array
Multiple items val int: value: 'T -> int (requires member op_Explicit)
-------------------- type int = int32
-------------------- type int<'Measure> = int
type 'T array = 'T array
module Array from Microsoft.FSharp.Collections
val min: array: 'T array -> 'T (requires comparison)
Throws System.ArgumentException.
|
Array.minBy projection array
Full Usage:
Array.minBy projection array
Parameters:
projection
:
'T -> 'U
-
The function to transform the elements into a type supporting comparison.
array
:
'T array
-
The input array.
Returns:
'T
The minimum element.
Modifiers:
inline
Type parameters:
'T, 'U (requires comparison)
|
Returns the lowest of all elements of the array, compared via Operators.min on the function result.
Returns the first minimal element of the array if there are multiple equal minimal elements.
Throws ArgumentException for empty arrays. This is an O(n) operation, where n is the length of the array.
-
projection
:
'T -> 'U
-
The function to transform the elements into a type supporting comparison.
-
array
:
'T array
-
The input array.
-
Returns:
'T
-
The minimum element.
Example
let inputs = [| "aaa"; "b"; "cccc" |]
inputs |> Array.minBy (fun s -> s.Length)
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
let inputs: string array= [| |]
inputs |> Array.minBy (fun s -> s.Length)
val inputs: string array
Multiple items val string: value: 'T -> string
-------------------- type string = System.String
type 'T array = 'T array
module Array from Microsoft.FSharp.Collections
val minBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Throws System.ArgumentException.
|
Array.ofList list
Full Usage:
Array.ofList list
Parameters:
list
:
'T list
-
The input list.
Returns:
'T array
The array of elements from the list.
Type parameters:
'T
|
Builds an array from the given list.
This is an O(n) operation, where n is the length of the list.
-
list
:
'T list
-
The input list.
-
Returns:
'T array
-
The array of elements from the list.
Example
let inputs = [ 1; 2; 5 ]
inputs |> Array.ofList
val inputs: int list
module Array from Microsoft.FSharp.Collections
val ofList: list: 'T list -> 'T array
Evaluates to [| 1; 2; 5 |].
|
Array.ofSeq source
Full Usage:
Array.ofSeq source
Parameters:
source
:
'T seq
-
The input sequence.
Returns:
'T array
The array of elements from the sequence.
Type parameters:
'T
|
Builds a new array from the given enumerable object.
This is an O(n) operation, where n is the length of the sequence.
-
source
:
'T seq
-
The input sequence.
-
Returns:
'T array
-
The array of elements from the sequence.
Example
let inputs = seq { 1; 2; 5 }
inputs |> Array.ofSeq
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 |].
[Page truncated to keep GeezerVison snappy.] |
|