Share via


Collections.Array Module (F#)

Provides basic operations on arrays.

Namespace/Module Path: Microsoft.FSharp.Collections

Assembly: FSharp.Core (in FSharp.Core.dll)

module Array

Remarks

For an overview of arrays in F#, see Arrays (F#).

Values

Value

Description

append : 'T [] -> 'T [] -> 'T []

Creates an array that contains the elements of one array followed by the elements of another array.

average : ^T [] -> ^T

Returns the average of the elements in an array.

averageBy : ('T -> ^U) -> 'T [] -> ^U

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

blit : 'T [] -> int -> 'T [] -> int -> int -> unit

Reads a range of elements from one array and writes them into another.

choose : ('T ->'U option) -> 'T [] -> 'U []

Applies a supplied function to each element of an array. Returns an array that contains the results x for each element for which the function returns Some(x).

collect : ('T -> 'U []) -> 'T [] -> 'U []

Applies the supplied function to each element of an array, concatenates the results, and returns the combined array.

concat : seq<'T []> -> 'T []

Creates an array that contains the elements of each of the supplied sequence of arrays.

copy : 'T -> 'T []

Creates an array that contains the elements of the supplied array.

create : int -> 'T -> 'T []

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

empty : 'T []

Returns an empty array of the given type.

exists : ('T -> bool) -> 'T [] -> bool

Tests whether any element of an array satisfies the supplied predicate.

exists2 : ('T1 -> 'T2 -> bool) -> 'T1 [] -> 'T2 [] -> bool

Tests whether any pair of corresponding elements of two arrays satisfy the supplied condition.

fill : 'T [] -> int -> int -> 'T -> unit

Fills a range of elements of an array with the supplied value.

filter : ('T -> bool) -> 'T [] -> 'T []

Returns a collection that contains only the elements of the supplied array for which the supplied condition returns true.

find : ('T -> bool) -> 'T [] -> 'T

Returns the first element for which the supplied function returns true. Raises KeyNotFoundException if no such element exists.

findIndex : ('T -> bool) -> 'T [] -> int

Returns the index of the first element in an array that satisfies the supplied condition. Raises KeyNotFoundException if none of the elements satisfy the condition.

fold : ('State -> 'T -> 'State) -> 'State -> 'T [] -> 'State

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

fold2 : ('State -> 'T1 -> 'T2 -> 'State) -> 'State -> 'T1 [] -> 'T2 [] -> 'State

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

foldBack : ('T -> 'State -> 'State) -> 'T [] -> 'State -> 'State

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

foldBack2 : ('T1 -> 'T2 -> 'State -> 'State) -> 'T1 [] -> 'T2 [] -> 'State -> 'State

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

forall : ('T -> bool) -> 'T [] -> bool

Tests whether all elements of an array satisfy the supplied condition.

forall2: ('T1 -> 'T2 -> bool) -> 'T1 [] -> 'T2 [] -> bool

Tests whether all corresponding elements of two supplied arrays satisfy a supplied condition.

get : 'T [] -> int -> 'T

Gets an element from an array.

init: int -> (int -> 'T) -> 'T []

Uses a supplied function to create an array of the supplied dimension.

isEmpty : 'T [] -> bool

Tests whether an array has any elements.

iter : ('T -> unit) -> 'T [] -> unit

Applies the supplied function to each element of an array.

iter2 : ('T1 -> 'T2 -> unit) -> 'T1 [] -> 'T2 [] -> unit)

Applies the supplied function to a pair of elements from matching indexes in two arrays. The two arrays must have the same lengths; otherwise, ArgumentException is raised.

iteri : (int -> 'T -> unit) -> 'T [] -> unit

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

iteri2 : (int -> 'T1 -> 'T2 -> unit) -> 'T1 [] -> 'T2 [] -> unit

Applies the supplied function to a pair of elements from matching indexes in two arrays, also passing the index of the elements. The two arrays must have the same lengths; otherwise, an ArgumentException is raised.

length : 'T [] -> int

Returns the length of an array. The Length property does the same thing.

map : ('T -> 'U) -> 'T [] -> 'U []

Creates an array whose elements are the results of applying the supplied function to each of the elements of a supplied array.

map2 : ('T1 -> 'T2 -> 'U) -> 'T1 [] -> 'T2 [] -> 'U []

Creates an array whose elements are the results of applying the supplied function to the corresponding elements of two supplied arrays. The two input arrays must have the same lengths; otherwise, ArgumentException is raised.

mapi : (int -> 'T -> 'U) -> 'T [] -> 'U []

Creates an array whose elements are the results of applying the supplied function to each of the elements of a supplied array. An integer index passed to the function indicates the index of the element being transformed.

mapi2 : (int -> 'T1 -> 'T2 -> 'U) -> 'T1 [] -> 'T2 [] -> 'U []

Creates an array whose elements are the results of applying the supplied 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, ArgumentException is raised.

max : 'T [] -> 'T

Returns the largest of all elements of an array. Operators.max is used to compare the elements.

maxBy : ('T -> 'U) -> 'T [] -> 'T

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

min : ('T [] -> 'T

Returns the smallest of all elements of an array. Operators.min is used to compare the elements.

minBy : ('T -> 'U) -> 'T [] -> 'T

Returns the smallest of all elements of an array. Operators.min is used to compare the elements.

ofList : 'T list -> 'T []

Creates an array from the supplied list.

ofSeq : seq<'T> -> 'T []

Creates an array from the supplied enumerable object.

partition : ('T -> bool) -> 'T [] -> 'T [] * 'T []

Splits an array into two arrays, one containing the elements for which the supplied condition returns true, and the other containing those for which it returns false.

permute : (int -> int) -> 'T [] -> 'T []

Permutes the elements of an array according to the specified permutation.

pick : ('T -> 'U option) -> 'T [] -> 'U

Applies the supplied function to successive elements of a supplied array, returning the first result where the function returns Some(x) for some x. If the function never returns Some(x), KeyNotFoundException is raised.

reduce : ('T -> 'T -> 'T) -> 'T [] -> 'T

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

reduceBack : ('T -> 'T -> 'T) -> 'T [] -> 'T

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

rev : 'T [] -> 'T []

Reverses the order of the elements in a supplied array.

scan : ('State -> 'T -> 'State) -> 'State -> 'T [] -> 'State [])

Behaves like fold, but returns the intermediate results together with the final results.

scanBack : ('T -> 'State -> 'State) -> 'T [] -> 'State -> 'State []

Behaves like foldBack, but returns the intermediary results together with the final results.

set : 'T [] -> int -> 'T -> unit

Sets an element of an array.

sort : 'T[] -> 'T []

Sorts the elements of an array and returns a new array. Operators.compare is used to compare the elements.

sortBy : ('T -> 'Key) -> 'T [] -> 'T []

Sorts the elements of an array by using the supplied function to transform the elements to the type on which the sort operation is based, and returns a new array. Operators.compare is used to compare the elements.

sortInPlace : 'T [] -> unit

Sorts the elements of an array by changing the array in place, using the supplied comparison function. Operators.compare is used to compare the elements.

sortInPlaceBy : ('T -> 'Key) -> 'T [] -> unit

Sorts the elements of an array by changing the array in place, using the supplied projection for the keys. Operators.compare is used to compare the elements.

sortInPlaceWith : ('T -> 'T -> int) -> 'T [] -> unit

Sorts the elements of an array by using the supplied comparison function to change the array in place.

sortWith : ('T -> 'T -> int) -> 'T [] -> 'T []

Sorts the elements of an array by using the supplied comparison function, and returns a new array.

sub : 'T [] -> int -> int -> 'T []

Creates an array that contains the supplied subrange, which is specified by starting index and length.

sum : 'T [] -> ^T

Returns the sum of the elements in the array.

sumBy : ('T -> ^U) -> 'T [] -> ^U

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

toList : 'T [] -> 'T list

Converts the supplied array to a list.

toSeq: 'T [] -> seq<'T>

Views the supplied array as a sequence.

tryFind : ('T -> bool) -> 'T [] -> 'T option

Returns the first element in the supplied array for which the supplied function returns true. Returns None if no such element exists.

tryFindIndex : ('T -> bool) -> 'T [] -> int option

Returns the index of the first element in an array that satisfies the supplied condition.

tryPick : ('T -> 'U option) -> 'T [] -> 'U option

Applies the supplied function to successive elements of the supplied array, and returns the first result where the function returns Some(x) for some x. If the function never returns Some(x), None is returned.

unzip : ('T1 * 'T2) [] -> 'T1 [] * 'T2 []

Splits an array of tuple pairs into a tuple of two arrays.

unzip3 : ('T1 * 'T2 * 'T3) [] -> 'T1 [] * 'T2 [] * 'T3 []

Splits an array of tuples of three elements into a tuple of three arrays.

zeroCreate : int -> 'T []

Creates an array whose elements are initially set to the default value Unchecked.defaultof<'T>.

zip : 'T1 [] -> 'T2 [] -> ('T1 * 'T2) []

Combines two arrays into an array of tuples that have two elements. The two arrays must have equal lengths; otherwise, ArgumentException is raised.

zip3 : 'T1 [] -> 'T2 [] -> 'T3 [] -> ('T1 * 'T2 * 'T3) []

Combines three arrays into an array of tuples that have three elements. The three arrays must have equal lengths; otherwise, ArgumentException is raised.

Platforms

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Reference

Microsoft.FSharp.Collections Namespace (F#)

Array

Collections.Array2D Module (F#)

Collections.Array3D Module (F#)

Collections.Array4D Module (F#)

Other Resources

Arrays (F#)