Array Module
The main module for functions on Array<'T>. This module provides additional functions to ones from FSharp.Core.Array module.
Functions and values
| Function or value |
Description
|
||
Full Usage:
asArray arr
Parameters:
ResizeArray<'T>
-
The input ResizeArray.
Returns: 'T[]
A fixed-length array.
Modifiers: inline Type parameters: 'T |
Return a fixed-length Array containing the elements of the input ResizeArray as a copy. When this function is used in Fable (JavaScript) the ResizeArray is just casted to an Array. In .NET a new Array is still allocated and the elements are copied.
|
||
Full Usage:
asResizeArray arr
Parameters:
'T[]
-
The input Array.
Returns: ResizeArray<'T>
A ResizeArray containing the same elements.
Modifiers: inline Type parameters: 'T |
Builds a new Array from the given ResizeArray. In Fable-JavaScript the ResizeArray is just casted to an Array without allocating a new ResizeArray.
|
||
Full Usage:
count arr
Parameters:
'T[]
-
The input Array.
Returns: int
The number of items in the Array.
Modifiers: inline Type parameters: 'T |
Return the length or count of the collection. Same as Array.length
|
||
Full Usage:
countIf predicate arr
Parameters:
'T -> bool
-
The function to test each element.
arr : 'T[]
-
The input Array.
Returns: int
The count of items for which the predicate returns true.
Modifiers: inline Type parameters: 'T |
Counts for how many items of the collection the predicate returns true. Same as Array.filter and then Array.length
|
||
Full Usage:
duplicates arr
Parameters:
'T[]
-
The input Array.
Returns: 'T[]
An array of duplicate elements.
|
Returns all elements that exists more than once in Array. Each element that exists more than once is only returned once. Returned order is by first occurrence of first duplicate.
|
||
Full Usage:
duplicatesBy f arr
Parameters:
'T -> 'U
-
The function to extract comparison value from each element.
arr : 'T[]
-
The input Array.
Returns: 'T[]
An array of duplicate elements.
|
Returns all elements that exists more than once in Array. Each element that exists more than once is only returned once. Returned order is by first occurrence of first duplicate.
|
||
Full Usage:
failIfEmpty errorMessage arr
Parameters:
string
-
The error message to include in the exception.
arr : 'T[]
-
The input Array.
Returns: 'T[]
The input Array if not empty.
Modifiers: inline Type parameters: 'T |
Raises an Exception if the Array is empty. (Useful for chaining) Returns the input Array
|
||
Full Usage:
failIfLessThan count errorMessage arr
Parameters:
int
-
The minimum count required.
errorMessage : string
-
The error message to include in the exception.
arr : 'T[]
-
The input Array.
Returns: 'T[]
The input Array if it has enough items.
|
Raises an Exception if the Array has less then count items. (Useful for chaining) Returns the input Array
|
||
Full Usage:
filteri predicate arr
Parameters:
int -> bool
-
The function to test the current index.
arr : 'T[]
-
The input array.
Returns: 'T[]
An array containing the elements for which the given predicate returns true.
|
Returns a new collection containing only the elements of the collection
for which the given predicate run on the index returns
|
||
Full Usage:
findArray searchFor fromIdx tillIdx searchIn
Parameters:
'T[]
-
The array pattern to search for.
fromIdx : int
-
The starting index for the search.
tillIdx : int
-
The ending index for the search.
searchIn : 'T[]
-
The array to search in.
Returns: int
The index of the first occurrence, or -1 if not found.
|
Find first index where searchFor array occurs in searchIn array. Give lower and upper bound index for search space. Returns index of first element or -1 if not found
|
||
Full Usage:
findLastArray searchFor fromIdx tillIdx searchIn
Parameters:
'T[]
-
The array pattern to search for.
fromIdx : int
-
The starting index for the search.
tillIdx : int
-
The ending index for the search.
searchIn : 'T[]
-
The array to search in.
Returns: int
The index of the last occurrence, or -1 if not found.
|
Find last index where searchFor array occurs in searchIn array. Searching from end. Give lower and upper bound index for search space. Returns index of first element or -1 if not found
|
||
Full Usage:
findLastValue searchFor fromIdx tillIdx searchIn
Parameters:
'T
-
The value to search for.
fromIdx : int
-
The starting index for the search.
tillIdx : int
-
The ending index for the search.
searchIn : 'T[]
-
The array to search in.
Returns: int
The index of the last occurrence, or -1 if not found.
|
Find last index where searchFor occurs in searchIn array. Searching from end. Give lower and upper bound index for search space. Returns -1 if not found
|
||
Full Usage:
findValue searchFor fromIdx tillIdx searchIn
Parameters:
'T
-
The value to search for.
fromIdx : int
-
The starting index for the search.
tillIdx : int
-
The ending index for the search.
searchIn : 'T[]
-
The array to search in.
Returns: int
The index of the first occurrence, or -1 if not found.
|
Find first index where searchFor occurs in searchIn array. Give lower and upper bound index for search space. Returns -1 if not found
|
||
Full Usage:
first arr
Parameters:
'T[]
-
The input Array.
Returns: 'T
The first item.
Modifiers: inline Type parameters: 'T |
Gets the first item in the Array. Same as this.[0]
|
||
Full Usage:
firstAndOnly arr
Parameters:
'T[]
-
The input Array.
Returns: 'T
The single item in the Array.
Modifiers: inline Type parameters: 'T |
Gets the only item in the Array. Fails if the Array does not have exactly one element.
|
||
Full Usage:
get index arr
Parameters:
int
-
The input index.
arr : 'T[]
-
The input Array.
Returns: 'T
The value of the Array at the given index.
Modifiers: inline Type parameters: 'T |
Gets an element from an Array. (Use Array.getNeg(i) function if you want to use negative indices too.)
|
||
Full Usage:
getLooped index arr
Parameters:
int
-
The index to access (can be any integer).
arr : 'T[]
-
The input Array.
Returns: 'T
The value at the looped index.
Modifiers: inline Type parameters: 'T |
Any index will return a value. Array is treated as an endless loop in positive and negative direction
|
||
Full Usage:
getNeg index arr
Parameters:
int
-
The index to access (can be negative).
arr : 'T[]
-
The input Array.
Returns: 'T
The value at the specified index.
Modifiers: inline Type parameters: 'T |
Gets an item in the Array by index. Allows for negative index too ( -1 is last item, like Python) (a negative index can also be done with '^' prefix. E.g. ^0 for the last item)
|
||
Full Usage:
hasItems count arr
Parameters:
int
-
The exact count to check for.
arr : 'T[]
-
The input Array.
Returns: bool
True if the Array has exactly the specified count.
Modifiers: inline Type parameters: 'T |
Returns true if the given Array has count items.
|
||
Full Usage:
hasMaximumItems count arr
Parameters:
int
-
The maximum count allowed.
arr : 'T[]
-
The input Array.
Returns: bool
True if the Array has at most the specified count.
Modifiers: inline Type parameters: 'T |
Returns true if the given Array has equal or less than count items.
|
||
Full Usage:
hasMinimumItems count arr
Parameters:
int
-
The minimum count required.
arr : 'T[]
-
The input Array.
Returns: bool
True if the Array has at least the specified count.
Modifiers: inline Type parameters: 'T |
Returns true if the given Array has equal or more than count items.
|
||
Full Usage:
hasOne arr
Parameters:
'T[]
-
The input Array.
Returns: bool
True if the Array has exactly one item.
Modifiers: inline Type parameters: 'T |
Returns true if the given Array has just one item. Same as Array.isSingleton
|
||
Full Usage:
iPrevThisNext arr
Parameters:
'T[]
-
The input Array.
Returns: (int * 'T * 'T * 'T) seq
A sequence of indexed consecutive triples (looped).
|
Yields looped Seq from (1, last, first, second) up to (lastIndex, second-last, last, first) The resulting seq has the same element count as the input Array.
|
||
Full Usage:
iThisNext arr
Parameters:
'T[]
-
The input Array.
Returns: (int * 'T * 'T) seq
A sequence of indexed consecutive pairs (looped).
|
Yields looped Seq from (0,first, second) up to (lastIndex, last, first). The resulting seq has the same element count as the input Array.
|
||
Full Usage:
isNotEmpty arr
Parameters:
'T[]
-
The input Array.
Returns: bool
True if the Array has at least one item.
Modifiers: inline Type parameters: 'T |
Returns true if the given Array is not empty.
|
||
Full Usage:
isSingleton arr
Parameters:
'T[]
-
The input Array.
Returns: bool
True if the Array has exactly one item.
Modifiers: inline Type parameters: 'T |
Returns true if the given Array has just one item. Same as Array.hasOne
|
||
Full Usage:
mapIfInputAndResult inputPredicate resultPredicate transform arr
Parameters:
'T[] -> bool
-
The predicate to test the input array.
resultPredicate : 'T[] -> bool
-
The predicate to test the result.
transform : 'T[] -> 'T[]
-
The transformation function to apply.
arr : 'T[]
-
The input Array.
Returns: 'T[]
The transformed array if conditions are met, otherwise the original array.
Modifiers: inline Type parameters: 'T |
Applies a function to array if it meets the inputPredicate, otherwise just returns input. If resulting array meets the resultPredicate it is returned, otherwise original input is returned.
|
||
Full Usage:
mapIfResult resultPredicate transform arr
Parameters:
'T[] -> bool
-
The predicate to test the result.
transform : 'T[] -> 'T[]
-
The transformation function to apply.
arr : 'T[]
-
The input Array.
Returns: 'T[]
The transformed array if it meets the predicate, otherwise the original array.
Modifiers: inline Type parameters: 'T |
Applies a function to array If resulting array meets the resultPredicate it is returned, otherwise the original input is returned.
|
||
Full Usage:
matches searchFor atIdx searchIn
Parameters:
'T[]
-
The array pattern to search for.
atIdx : int
-
The index to start the search.
searchIn : 'T[]
-
The array to search in.
Returns: bool
True if the pattern matches at the given index.
|
Checks if a given array matches the content in Array at a given index
|
||
Full Usage:
max2 arr
Parameters:
'T[]
-
The input Array.
Returns: 'T * 'T
A tuple of the biggest and second biggest elements.
Modifiers: inline Type parameters: 'T |
Returns the biggest and the second biggest element of the Array. If they are equal then the order is kept
|
||
Full Usage:
max2By f arr
Parameters:
'T -> 'Key
-
The function to transform elements for comparison.
arr : 'T[]
-
The input Array.
Returns: 'T * 'T
A tuple of the biggest and second biggest elements.
Modifiers: inline Type parameters: 'T, 'Key |
Returns the biggest and the second biggest element of the Array. Elements are compared by applying the predicate function first. If they are equal after function is applied then the order is kept
|
||
Full Usage:
max2IndicesBy f arr
Parameters:
'T -> 'Key
-
The function to transform elements for comparison.
arr : 'T[]
-
The input Array.
Returns: int * int
A tuple of the indices of the biggest and second biggest elements.
Modifiers: inline Type parameters: 'T, 'Key |
Returns the indices of the biggest and the second biggest element of the Array. Elements are compared by applying the predicate function first. If they are equal after function is applied then the order is kept
|
||
Full Usage:
max3 arr
Parameters:
'T[]
-
The input Array.
Returns: 'T * 'T * 'T
A tuple of the three biggest elements.
Modifiers: inline Type parameters: 'T |
Returns the biggest three elements of the Array. The first element is the biggest, the second is the second biggest and the third is the third biggest. If they are equal then the order is kept
|
||
Full Usage:
max3By f arr
Parameters:
'T -> 'Key
-
The function to transform elements for comparison.
arr : 'T[]
-
The input Array.
Returns: 'T * 'T * 'T
A tuple of the three biggest elements.
Modifiers: inline Type parameters: 'T, 'Key |
Returns the biggest three elements of the Array. The first element is the biggest, the second is the second biggest and the third is the third biggest. Elements are compared by applying the predicate function first. If they are equal after function is applied then the order is kept
|
||
Full Usage:
max3IndicesBy f arr
Parameters:
'T -> 'Key
-
The function to transform elements for comparison.
arr : 'T[]
-
The input Array.
Returns: int * int * int
A tuple of the indices of the three biggest elements.
Modifiers: inline Type parameters: 'T, 'Key |
Returns the indices of the three biggest elements of the Array. The first element is the index of the biggest, the second is the index of the second biggest and the third is the index of the third biggest. Elements are compared by applying the predicate function first. If they are equal after function is applied then the order is kept
|
||
Full Usage:
maxIndexBy projection arr
Parameters:
'T -> 'Key
-
The function to transform the elements into a type supporting comparison.
arr : 'T[]
-
The input Array.
Returns: int
The index of the maximum element.
Modifiers: inline Type parameters: 'T, 'Key |
Returns the index of the greatest of all elements of the Array, compared via Operators.max on the function result.
|
||
Full Usage:
min2 arr
Parameters:
'T[]
-
The input Array.
Returns: 'T * 'T
A tuple of the smallest and second smallest elements.
Modifiers: inline Type parameters: 'T |
Returns the smallest and the second smallest element of the Array. If they are equal then the order is kept
|
||
Full Usage:
min2By f arr
Parameters:
'T -> 'Key
-
The function to transform elements for comparison.
arr : 'T[]
-
The input Array.
Returns: 'T * 'T
A tuple of the smallest and second smallest elements.
Modifiers: inline Type parameters: 'T, 'Key |
Returns the smallest and the second smallest element of the Array. Elements are compared by applying the predicate function first. If they are equal after function is applied then the order is kept
|
||
Full Usage:
min2IndicesBy f arr
Parameters:
'T -> 'Key
-
The function to transform elements for comparison.
arr : 'T[]
-
The input Array.
Returns: int * int
A tuple of the indices of the smallest and second smallest elements.
Modifiers: inline Type parameters: 'T, 'Key |
Returns the indices of the smallest and the second smallest element of the Array. Elements are compared by applying the predicate function first. If they are equal after function is applied then the order is kept
|
||
Full Usage:
min3 arr
Parameters:
'T[]
-
The input Array.
Returns: 'T * 'T * 'T
A tuple of the three smallest elements.
Modifiers: inline Type parameters: 'T |
Returns the smallest three elements of the Array. The first element is the smallest, the second is the second smallest and the third is the third smallest. If they are equal then the order is kept
|
||
Full Usage:
min3By f arr
Parameters:
'T -> 'Key
-
The function to transform elements for comparison.
arr : 'T[]
-
The input Array.
Returns: 'T * 'T * 'T
A tuple of the three smallest elements.
Modifiers: inline Type parameters: 'T, 'Key |
Returns the smallest three elements of the Array. The first element is the smallest, the second is the second smallest and the third is the third smallest. Elements are compared by applying the predicate function first. If they are equal after function is applied then the order is kept
|
||
Full Usage:
min3IndicesBy f arr
Parameters:
'T -> 'Key
-
The function to transform elements for comparison.
arr : 'T[]
-
The input Array.
Returns: int * int * int
A tuple of the indices of the three smallest elements.
Modifiers: inline Type parameters: 'T, 'Key |
Returns the indices of the three smallest elements of the Array. The first element is the index of the smallest, the second is the index of the second smallest and the third is the index of the third smallest. Elements are compared by applying the predicate function first. If they are equal after function is applied then the order is kept
|
||
Full Usage:
minIndexBy projection arr
Parameters:
'T -> 'Key
-
The function to transform the elements into a type supporting comparison.
arr : 'T[]
-
The input Array.
Returns: int
The index of the smallest element.
Modifiers: inline Type parameters: 'T, 'Key |
Returns the index of the smallest of all elements of the Array, compared via Operators.max on the function result.
|
||
Full Usage:
ofIList arr
Parameters:
IList<'T>
-
The input IList.
Returns: 'T[]
A new array containing the elements from the IList.
Modifiers: inline Type parameters: 'T |
Build a Array from the given IList Interface.
|
||
Full Usage:
ofResizeArray rarr
Parameters:
ResizeArray<'T>
-
The input ResizeArray.
Returns: 'T[]
A new array containing the elements from the ResizeArray.
Modifiers: inline Type parameters: 'T |
Builds a new Array from the given ResizeArray. (Use the asArray function if you want to just cast an ResizeArray to a Array in Fable-JavaScript)
|
||
Full Usage:
prevThis arr
Parameters:
'T[]
-
The input Array.
Returns: ('T * 'T) seq
A sequence of consecutive pairs (looped).
|
Yields looped Seq from (last,first) up to (second-last, last). The resulting seq has the same element count as the input Array.
|
||
Full Usage:
prevThisNext arr
Parameters:
'T[]
-
The input Array.
Returns: ('T * 'T * 'T) seq
A sequence of consecutive triples (looped).
|
Yields looped Seq of from (last, first, second) up to (second-last, last, first). The resulting seq has the same element count as the input Array.
|
||
Full Usage:
rotate amount arr
Parameters:
int
-
How many elements to shift forward. Or backward if number is negative
arr : 'T[]
-
The input Array.
Returns: 'T[]
The new result Array.
Modifiers: inline Type parameters: 'T |
Considers array circular and move elements up for positive integers or down for negative integers. e.g.: rotate +1 [ a, b, c, d] = [ d, a, b, c] e.g.: rotate -1 [ a, b, c, d] = [ b, c, d, a] the amount can even be bigger than the array's size. I will just rotate more than one loop.
|
||
Full Usage:
rotateDownTill condition arr
Parameters:
'T -> bool
-
The condition to meet.
arr : 'T[]
-
The input Array.
Returns: 'T[]
The new result Array.
Modifiers: inline Type parameters: 'T |
Considers array circular and move elements down till condition is met for the first item. The algorithm takes elements from the start and put them at the end till the first element in the array meets the condition. If the first element in the input meets the condition no changes are made. But still a shallow copy is returned.
|
||
Full Usage:
rotateDownTillLast condition arr
Parameters:
'T -> bool
-
The condition to meet.
arr : 'T[]
-
The input Array.
Returns: 'T[]
The new result Array.
Modifiers: inline Type parameters: 'T |
Considers array circular and move elements down till condition is met for the last item. The algorithm takes elements from the start and put them at the end till the last element in the array meets the condition. If the last element in the input meets the condition no changes are made. But still a shallow copy is returned.
|
||
Full Usage:
rotateUpTill condition arr
Parameters:
'T -> bool
-
The condition to meet.
arr : 'T[]
-
The input Array.
Returns: 'T[]
The new result Array.
Modifiers: inline Type parameters: 'T |
Considers array circular and move elements up till condition is met for the first item. The algorithm takes elements from the end and put them at the start till the first element in the array meets the condition. If the first element in the input meets the condition no changes are made. But still a shallow copy is returned.
|
||
Full Usage:
rotateUpTillLast condition arr
Parameters:
'T -> bool
-
The condition to meet.
arr : 'T[]
-
The input Array.
Returns: 'T[]
The new result Array.
Modifiers: inline Type parameters: 'T |
Considers array circular and move elements up till condition is met for the last item. The algorithm takes elements from the end and put them at the start till the last element in the array meets the condition. If the last element in the input meets the condition no changes are made. But still a shallow copy is returned.
|
||
Full Usage:
second arr
Parameters:
'T[]
-
The input Array.
Returns: 'T
The second item.
Modifiers: inline Type parameters: 'T |
Gets the second item in the Array. Same as this.[1]
|
||
Full Usage:
secondLast arr
Parameters:
'T[]
-
The input Array.
Returns: 'T
The second last item.
Modifiers: inline Type parameters: 'T |
Gets the second last item in the Array. Same as this.[this.Length - 2]
|
||
Full Usage:
set index value arr
Parameters:
int
-
The input index.
value : 'T
-
The input value.
arr : 'T[]
-
The input Array.
Modifiers: inline Type parameters: 'T |
Sets an element of a Array. (use Array.setNeg(i) function if you want to use negative indices too)
|
||
Full Usage:
setLooped index value arr
Parameters:
int
-
The index to set (can be any integer).
value : 'T
-
The value to set.
arr : 'T[]
-
The input Array.
Modifiers: inline Type parameters: 'T |
Any index will set a value. Array is treated as an endless loop in positive and negative direction
|
||
Full Usage:
setNeg index value arr
Parameters:
int
-
The index to set (can be negative).
value : 'T
-
The value to set.
arr : 'T[]
-
The input Array.
Modifiers: inline Type parameters: 'T |
Sets an item in the Array by index. Allows for negative index too ( -1 is last item, like Python) (a negative index can also be done with '^' prefix. E.g. ^0 for the last item)
|
||
Full Usage:
singleton value
Parameters:
'T
-
The input item.
Returns: 'T[]
The result Array of one item.
Modifiers: inline Type parameters: 'T |
Returns a Array that contains one item only.
|
||
Full Usage:
slice startIdx endIdx arr
Parameters:
int
-
The start index (inclusive, can be negative).
endIdx : int
-
The end index (inclusive, can be negative).
arr : 'T[]
-
The input Array.
Returns: 'T[]
A new array containing the sliced elements.
|
Slice the Array given start and end index. Allows for negative indices too. ( -1 is last item, like Python) The resulting Array includes the end index. Raises an IndexOutOfRangeException if indices are out of range. If you don't want an exception to be raised for index overflow or overlap use Array.trim. (A negative index can also be done with '^' prefix. E.g. ^0 for the last item, when F# Language preview features are enabled.)
|
||
Full Usage:
swap i j arr
Parameters:
int
-
The first index to swap.
j : int
-
The second index to swap.
arr : 'T[]
-
The input Array.
Modifiers: inline Type parameters: 'T |
Swap the values of two given indices in Array
|
||
Full Usage:
third arr
Parameters:
'T[]
-
The input Array.
Returns: 'T
The third item.
Modifiers: inline Type parameters: 'T |
Gets the third item in the Array. Same as this.[2]
|
||
Full Usage:
thirdLast arr
Parameters:
'T[]
-
The input Array.
Returns: 'T
The third last item.
Modifiers: inline Type parameters: 'T |
Gets the third last item in the Array. Same as this.[this.Length - 3]
|
||
Full Usage:
thisNext arr
Parameters:
'T[]
-
The input Array.
Returns: ('T * 'T) seq
A sequence of consecutive pairs (looped).
|
Yields looped Seq from (first, second) up to (last, first). The resulting seq has the same element count as the input Array.
|
||
Full Usage:
toResizeArray arr
Parameters:
'T[]
-
The input Array.
Returns: ResizeArray<'T>
A ResizeArray containing a copy of the Array elements.
Modifiers: inline Type parameters: 'T |
Return a fixed-length Array containing the elements of the input Array as a copy. This function always allocates a new ResizeArray and copies the elements. (Use the asArray function if you want to just cast a Array to an Array in Fable-JavaScript)
|
||
Full Usage:
trim fromStartCount fromEndCount arr
Parameters:
int
-
The number of items to remove from the start.
fromEndCount : int
-
The number of items to remove from the end.
arr : 'T[]
-
The input Array.
Returns: 'T[]
A new trimmed array.
|
Trim items from start and end. If the sum of fromStartCount and fromEndCount is bigger than arr.Length it returns an empty Array. If you want an exception to be raised for index overlap (total trimming is bigger than count) use Array.slice with negative end index.
|
||
Full Usage:
windowed2 arr
Parameters:
'T[]
-
The input Array.
Returns: ('T * 'T) seq
A sequence of consecutive pairs.
|
Yields Seq from (first, second) up to (second-last, last). Not looped. The resulting seq is one element shorter than the input Array.
|
||
Full Usage:
windowed2i arr
Parameters:
'T[]
-
The input Array.
Returns: (int * 'T * 'T) seq
A sequence of consecutive indexed pairs.
|
Yields Seq from (0,first, second) up to (lastIndex-1 , second-last, last). Not looped. The resulting seq is one element shorter than the input Array.
|
||
Full Usage:
windowed3 arr
Parameters:
'T[]
-
The input Array.
Returns: ('T * 'T * 'T) seq
A sequence of consecutive triples.
|
Yields Seq from (first, second, third) up to (third-last, second-last, last). Not looped. The resulting seq is two elements shorter than the input Array.
|
||
Full Usage:
windowed3i arr
Parameters:
'T[]
-
The input Array.
Returns: (int * 'T * 'T * 'T) seq
A sequence of consecutive indexed triples.
|
Yields Seq from (1, first, second, third) up to (lastIndex-1 , third-last, second-last, last). Not looped. The resulting seq is two elements shorter than the input Array.
|
ArrayT