Array Module
Contains operations for working with arrays.
See also F# Language Guide - Arrays.
Nested modules
Modules | Description |
Functions and values
Function or value | Description | ||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val allPairs: array1: 'T1 array -> array2: 'T2 array -> ('T1 * 'T2) array
Evaluates to
|
||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val append: array1: 'T array -> array2: 'T array -> 'T array
Evaluates to [| 1; 2; 3; 4 |] .
|
||||||
Full Usage:
Array.average array
Parameters:
^T array
-
The input array.
Returns: ^T
The average of the elements in the array.
Modifiers: inline Type parameters: ^T |
Example
module Array
from Microsoft.FSharp.Collections
val average: array: 'T array -> 'T (requires member (+) and member DivideByInt and member Zero)
Evaluates to 3.0
Example
module Array
from Microsoft.FSharp.Collections
val average: array: 'T array -> 'T (requires member (+) and member DivideByInt and member Zero)
Throws ArgumentException
|
||||||
Full Usage:
Array.averageBy projection array
Parameters:
'T -> ^U
-
The function to transform the array elements before averaging.
array : 'T array
-
The input array.
Returns: ^U
The computed average.
Modifiers: inline Type parameters: 'T, ^U |
Example
type Foo =
{ Bar: float }
Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float val input: Foo array
module Array
from Microsoft.FSharp.Collections
val averageBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member DivideByInt and member Zero)
val foo: Foo
Foo.Bar: float
Evaluates to 3.0
Example
type Foo =
{ Bar: float }
Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float val input: Foo array
type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val averageBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member DivideByInt and member Zero)
val foo: Foo
Foo.Bar: float
Throws ArgumentException
|
||||||
Full Usage:
Array.blit source sourceIndex target targetIndex count
Parameters:
'T array
-
The source array.
sourceIndex : int
-
The starting index of the source array.
target : 'T array
-
The target array.
targetIndex : int
-
The starting index of the target array.
count : int
-
The number of elements to copy.
Modifiers: inline Type parameters: 'T |
Slicing syntax is generally preferred, e.g.
val source: int array
val target: int array
Example
val source: int array
val target: int array
module Array
from Microsoft.FSharp.Collections
val blit: source: 'T array -> sourceIndex: int -> target: 'T array -> targetIndex: int -> count: int -> unit
After evaluation target contains [| 0; 1; 2; 13; 14; 5 |] .
|
||||||
|
Example
val input: int option array
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
module Array
from Microsoft.FSharp.Collections
val choose: chooser: ('T -> 'U option) -> array: 'T array -> 'U array
val id: x: 'T -> 'T
Evaluates to [| 1; 2 |]
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val choose: chooser: ('T -> 'U option) -> array: 'T array -> 'U array
val n: int
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
Evaluates to [| 2 |]
|
||||||
|
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val chunkBySize: chunkSize: int -> array: 'T array -> 'T array array
Evaluates to [| [|1; 2|]; [|3|] |]
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val chunkBySize: chunkSize: int -> array: 'T array -> 'T array array
Throws ArgumentException
|
||||||
|
Example
type Foo =
{ Bar: int array }
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
val input: Foo array
module Array
from Microsoft.FSharp.Collections
val collect: mapping: ('T -> 'U array) -> array: 'T array -> 'U array
val foo: Foo
Foo.Bar: int array
Evaluates to [| 1; 2; 3; 4 |]
Example
val input: int list list
module Array
from Microsoft.FSharp.Collections
val collect: mapping: ('T -> 'U array) -> array: 'T array -> 'U array
val id: x: 'T -> 'T
Evaluates to [| 1; 2; 3; 4 |]
|
||||||
Full Usage:
Array.compareWith comparer array1 array2
Parameters:
'T -> 'T -> int
-
A function that takes an element from each array and returns an int.
If it evaluates to a non-zero value iteration is stopped and that value is returned.
array1 : 'T array
-
The first input array.
array2 : 'T array
-
The second input array.
Returns: int
Returns the first non-zero result from the comparison function. If the first array has
a larger element, the return value is always positive. If the second array has a larger
element, the return value is always negative. When the elements are equal in the two
arrays, 1 is returned if the first array is longer, 0 is returned if they are equal in
length, and -1 is returned when the second array is longer.
Modifiers: inline Type parameters: 'T |
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int array
val input2: int array
module Array
from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> array1: 'T array -> array2: 'T array -> int
Evaluates to 0
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int array
val input2: int array
module Array
from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> array1: 'T array -> array2: 'T array -> int
Evaluates to -1
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int array
val input2: int array
module Array
from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> array1: 'T array -> array2: 'T array -> int
Evaluates to 1
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int array
val input2: int array
module Array
from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> array1: 'T array -> array2: 'T array -> int
Evaluates to 1
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int array
val input2: int array
module Array
from Microsoft.FSharp.Collections
val compareWith: comparer: ('T -> 'T -> int) -> array1: 'T array -> array2: 'T array -> int
Evaluates to -1
|
||||||
|
Example
val inputs: int array list
module Array
from Microsoft.FSharp.Collections
val concat: arrays: 'T array seq -> 'T array
Evaluates to [| 1; 2; 3; 4; 5 |]
|
||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val contains: value: 'T -> array: 'T array -> bool (requires equality)
|
||||||
|
Example
val source: int array
module Array
from Microsoft.FSharp.Collections
val copy: array: 'T array -> 'T array
Evaluates to a new array containing[| 12; 13; 14 |] .
|
||||||
|
Example
type Foo =
{ Bar: string }
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val inputs: Foo array
module Array
from Microsoft.FSharp.Collections
val countBy: projection: ('T -> 'Key) -> array: 'T array -> ('Key * int) array (requires equality)
val foo: Foo
Foo.Bar: string
Evaluates to [| ("a", 2); ("b", 1) |]
|
||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val create: count: int -> value: 'T -> 'T array
Evaluates to a new array containing[| "a"; "a"; "a"; "a" |] .
Example
val cell: string ref
Multiple items
val ref: value: 'T -> 'T ref -------------------- type 'T ref = Ref<'T> Multiple items
val array: string ref array -------------------- type 'T array = 'T array module Array
from Microsoft.FSharp.Collections
val create: count: int -> value: 'T -> 'T array
property Ref.Value: string with get, set
Before evaluation of the last line, array contains[| { contents = "a"}; { contents = "a"} |] .
After evaluation of the last line array contains[| { contents = "b"}; { contents = "b"} |] .
Note each entry in the array is the same mutable cell object.
|
||||||
|
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val distinct: array: 'T array -> 'T array (requires equality)
Evaluates to [| 1; 2; 3 |]
|
||||||
|
Example
val inputs: obj array
module Array
from Microsoft.FSharp.Collections
val distinctBy: projection: ('T -> 'Key) -> array: 'T array -> 'T array (requires equality)
val foo: obj
Evaluates to [| { Bar = 1 }; { Bar = 2 }; { Bar = 3 } |]
|
||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val empty<'T> : 'T array
|
||||||
Full Usage:
Array.exactlyOne array
Parameters:
'T array
-
The input array.
Returns: 'T
The only element of the array.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val exactlyOne: array: 'T array -> 'T
Evaluates to banana
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val exactlyOne: array: 'T array -> 'T
Throws ArgumentException
Example
val inputs: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val exactlyOne: array: 'T array -> 'T
Throws ArgumentException
|
||||||
Full Usage:
Array.except itemsToExclude array
Parameters:
'T seq
-
A sequence whose elements that also occur in the input array will cause those elements to be
removed from the result.
array : 'T array
-
An array whose elements that are not also in itemsToExclude will be returned.
Returns: 'T array
An array that contains the distinct elements of array that do not appear in itemsToExclude .
|
Example
val original: int array
val itemsToExclude: int array
module Array
from Microsoft.FSharp.Collections
val except: itemsToExclude: 'T seq -> array: 'T array -> 'T array (requires equality)
Evaluates to [| 2; 4 |]
|
||||||
|
The predicate is applied to the elements of the input array. If any application returns true then the overall result is true and no further elements are tested. Otherwise, false is returned.
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val exists: predicate: ('T -> bool) -> array: 'T array -> bool
val elm: int
Evaluates to true
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val exists: predicate: ('T -> bool) -> array: 'T array -> bool
val elm: int
Evaluates to false
|
||||||
|
The predicate is applied to matching elements in the two collections up to the lesser of the
two lengths of the collections. If any application returns true then the overall result is
true and no further elements are tested. Otherwise, if one collections is longer
than the other then the
Example
val inputs1: int array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val exists2: predicate: ('T1 -> 'T2 -> bool) -> array1: 'T1 array -> array2: 'T2 array -> bool
val a: int
val b: int
Evaluates to false
Example
val inputs1: int array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val exists2: predicate: ('T1 -> 'T2 -> bool) -> array1: 'T1 array -> array2: 'T2 array -> bool
val a: int
val b: int
Evaluates to true
|
||||||
|
Example
val target: int array
module Array
from Microsoft.FSharp.Collections
val fill: target: 'T array -> targetIndex: int -> count: int -> value: 'T -> unit
After evaluation target contains [| 0; 1; 2; 100; 100; 5 |] .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val filter: predicate: ('T -> bool) -> array: 'T array -> 'T array
val elm: int
Evaluates to [| 2; 4 |]
|
||||||
|
Returns the first element for which the given function returns 'true'. Raise KeyNotFoundException if no such element exists.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val find: predicate: ('T -> bool) -> array: 'T array -> 'T
val elm: int
Evaluates to 2
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val find: predicate: ('T -> bool) -> array: 'T array -> 'T
val elm: int
Throws KeyNotFoundException
|
||||||
|
Returns the last element for which the given function returns 'true'. Raise KeyNotFoundException if no such element exists.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findBack: predicate: ('T -> bool) -> array: 'T array -> 'T
val elm: int
Evaluates to 4
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findBack: predicate: ('T -> bool) -> array: 'T array -> 'T
val elm: int
Throws KeyNotFoundException
|
||||||
|
Returns the index of the first element in the array that satisfies the given predicate. Raise KeyNotFoundException if none of the elements satisfy the predicate.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> array: 'T array -> int
val elm: int
Evaluates to 1
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> array: 'T array -> int
val elm: int
Throws KeyNotFoundException
|
||||||
|
Returns the index of the last element in the array that satisfies the given predicate. Raise KeyNotFoundException if none of the elements satisfy the predicate.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> array: 'T array -> int
val elm: int
Evaluates to 3
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val findIndex: predicate: ('T -> bool) -> array: 'T array -> int
val elm: int
Throws KeyNotFoundException
|
||||||
Full Usage:
Array.fold folder state array
Parameters:
'State -> 'T -> 'State
-
The function to update the state given the input elements.
state : 'State
-
The initial state.
array : 'T array
-
The input array.
Returns: 'State
The final state.
|
Example
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge array
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
module Array
from Microsoft.FSharp.Collections
val fold<'T,'State> : folder: ('State -> 'T -> 'State) -> state: 'State -> array: 'T array -> 'State
val acc: int
val charge: Charge
val i: int
val o: int
Evaluates to 2
|
||||||
Full Usage:
Array.fold2 folder state array1 array2
Parameters:
'State -> 'T1 -> 'T2 -> 'State
-
The function to update the state given the input elements.
state : 'State
-
The initial state.
array1 : 'T1 array
-
The first input array.
array2 : 'T2 array
-
The second input array.
Returns: 'State
The final state.
|
Example
type CoinToss =
| Head
| Tails
val data1: CoinToss array
union case CoinToss.Tails: CoinToss
union case CoinToss.Head: CoinToss
val data2: CoinToss array
module Array
from Microsoft.FSharp.Collections
val fold2<'T1,'T2,'State> : folder: ('State -> 'T1 -> 'T2 -> 'State) -> state: 'State -> array1: 'T1 array -> array2: 'T2 array -> 'State
val acc: int
val a: CoinToss
val b: CoinToss
Evaluates to 1
|
||||||
Full Usage:
Array.foldBack folder array state
Parameters:
'T -> 'State -> 'State
-
The function to update the state given the input elements.
array : 'T array
-
The input array.
state : 'State
-
The initial state.
Returns: 'State
The state object after the folding function is applied to each element of the array.
|
Example
type Count =
{
Positive: int
Negative: int
Text: string
}
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int Multiple items
val string: value: 'T -> string -------------------- type string = System.String val sequence: int array
val initialState: Count
module Array
from Microsoft.FSharp.Collections
val foldBack: folder: ('T -> 'State -> 'State) -> array: 'T array -> state: 'State -> 'State
val a: int
val acc: Count
val text: string
Count.Text: string
Count.Positive: int
Count.Negative: int
Evaluates to
namespace Microsoft.FSharp.Text
|
||||||
Full Usage:
Array.foldBack2 folder array1 array2 state
Parameters:
'T1 -> 'T2 -> 'State -> 'State
-
The function to update the state given the input elements.
array1 : 'T1 array
-
The first input array.
array2 : 'T2 array
-
The second input array.
state : 'State
-
The initial state.
Returns: 'State
The final state.
|
Example
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int namespace Microsoft.FSharp.Text
Multiple items
val string: value: 'T -> string -------------------- type string = System.String module Array
from Microsoft.FSharp.Collections
val foldBack2: folder: ('T1 -> 'T2 -> 'State -> 'State) -> array1: 'T1 array -> array2: 'T2 array -> state: 'State -> 'State
Evaluates to
namespace Microsoft.FSharp.Text
|
||||||
|
The predicate is applied to the elements of the input collection. If any application returns false then the overall result is false and no further elements are tested. Otherwise, true is returned.
Example
val isEven: a: int -> bool
val a: int
module Array
from Microsoft.FSharp.Collections
val forall: predicate: ('T -> bool) -> array: 'T array -> bool
|
||||||
|
The predicate is applied to matching elements in the two collections up to the lesser of the
two lengths of the collections. If any application returns false then the overall result is
false and no further elements are tested. Otherwise, if one collection is longer
than the other then the
Example
val inputs1: int array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val forall2: predicate: ('T1 -> 'T2 -> bool) -> array1: 'T1 array -> array2: 'T2 array -> bool
Evaluates to true .
Example
val items1: int array
val items2: int array
module Array
from Microsoft.FSharp.Collections
val forall2: predicate: ('T1 -> 'T2 -> bool) -> array1: 'T1 array -> array2: 'T2 array -> bool
Evaluates to false .
Example
val items1: int array
val items2: int array
module Array
from Microsoft.FSharp.Collections
val forall2: predicate: ('T1 -> 'T2 -> bool) -> array1: 'T1 array -> array2: 'T2 array -> bool
Throws ArgumentException .
|
||||||
|
Normally the syntax
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val get: array: 'T array -> index: int -> 'T
Evaluates to "b"
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val get: array: 'T array -> index: int -> 'T
Throws IndexOutOfRangeException
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val groupBy: projection: ('T -> 'Key) -> array: 'T array -> ('Key * 'T array) array (requires equality)
val n: int
Evaluates to [| (1, [| 1; 3; 5 |]); (0, [| 2; 4 |]) |]
|
||||||
Full Usage:
Array.head array
Parameters:
'T array
-
The input array.
Returns: 'T
The first element of the array.
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val head: array: 'T array -> 'T
Evaluates to banana
Example
module Array
from Microsoft.FSharp.Collections
val head: array: 'T array -> 'T
Throws ArgumentException
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val indexed: array: 'T array -> (int * 'T) array
Evaluates to [| (0, "a"); (1, "b"); (2, "c") |]
|
||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val init: count: int -> initializer: (int -> 'T) -> 'T array
val v: int
Evaluates to [| 5; 6; 7; 8 |]
Example
module Array
from Microsoft.FSharp.Collections
val init: count: int -> initializer: (int -> 'T) -> 'T array
val v: int
Throws ArgumentException
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val insertAt: index: int -> value: 'T -> source: 'T array -> 'T array
Evaluates to [| 0; 9; 1; 2 |] .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val insertManyAt: index: int -> values: 'T seq -> source: 'T array -> 'T array
Evaluates to [| 0; 8; 9; 1; 2 |] .
|
||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val isEmpty: array: 'T array -> bool
Evaluates to true
Example
module Array
from Microsoft.FSharp.Collections
val isEmpty: array: 'T array -> bool
Evaluates to false
|
||||||
|
Normally the syntax
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val item: index: int -> array: 'T array -> 'T
Evaluates to "b"
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val item: index: int -> array: 'T array -> 'T
Throws ArgumentException
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val iter: action: ('T -> unit) -> array: 'T array -> unit
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||||
|
Example
val inputs1: string array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val iter2: action: ('T1 -> 'T2 -> unit) -> array1: 'T1 array -> array2: 'T2 array -> unit
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val iteri: action: (int -> 'T -> unit) -> array: 'T array -> unit
val i: int
val v: string
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||||
|
Example
val inputs1: string array
val inputs2: string array
module Array
from Microsoft.FSharp.Collections
val iteri2: action: (int -> 'T1 -> 'T2 -> unit) -> array1: 'T1 array -> array2: 'T2 array -> unit
val i: int
val s1: string
val s2: string
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||||
Full Usage:
Array.last array
Parameters:
'T array
-
The input array.
Returns: 'T
The last element of the array.
Modifiers: inline Type parameters: 'T |
Example
module Array
from Microsoft.FSharp.Collections
val last: array: 'T array -> 'T
Evaluates to banana
Example
module Array
from Microsoft.FSharp.Collections
val last: array: 'T array -> 'T
Throws ArgumentException
|
||||||
|
The notation
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val length: array: 'T array -> int
Evaluates to 3
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val x: string
property System.String.Length: int with get
Evaluates to [| 1; 3; 2 |]
|
||||||
|
Example
val inputs1: string array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val map2: mapping: ('T1 -> 'T2 -> 'U) -> array1: 'T1 array -> array2: 'T2 array -> 'U array
val x: string
val y: int
Evaluates to [| 'a'; 'd'; 'o' |]
|
||||||
Full Usage:
Array.map3 mapping array1 array2 array3
Parameters:
'T1 -> 'T2 -> 'T3 -> 'U
-
The function to transform the pairs of the input elements.
array1 : 'T1 array
-
The first input array.
array2 : 'T2 array
-
The second input array.
array3 : 'T3 array
-
The third input array.
Returns: 'U array
The array of transformed elements.
|
Example
val inputs1: string array
val inputs2: string array
val inputs3: string array
module Array
from Microsoft.FSharp.Collections
val map3: mapping: ('T1 -> 'T2 -> 'T3 -> 'U) -> array1: 'T1 array -> array2: 'T2 array -> array3: 'T3 array -> 'U array
val x: string
val y: string
val z: string
Evaluates to [| "all"; "the"; "time" |]
|
||||||
Full Usage:
Array.mapFold mapping state array
Parameters:
'State -> 'T -> 'Result * 'State
-
The function to transform elements from the input array and accumulate the final value.
state : 'State
-
The initial state.
array : 'T array
-
The input array.
Returns: 'Result array * 'State
The array of transformed elements, and the final accumulated value.
|
Example
Multiple items
val double: value: 'T -> double (requires member op_Explicit) -------------------- type double = System.Double -------------------- type double<'Measure> = float<'Measure> Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module Array
from Microsoft.FSharp.Collections
val mapFold<'T,'State,'Result> : mapping: ('State -> 'T -> 'Result * 'State) -> state: 'State -> array: 'T array -> 'Result array * 'State
Evaluates newCharges to [|In 2; Out 4; In 6|] and balance to 2 .
|
||||||
Full Usage:
Array.mapFoldBack mapping array state
Parameters:
'T -> 'State -> 'Result * 'State
-
The function to transform elements from the input array and accumulate the final value.
array : 'T array
-
The input array.
state : 'State
-
The initial state.
Returns: 'Result array * 'State
The array of transformed elements, and the final accumulated value.
|
ExampleAccumulate the charges from back to front, and double them as well
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge array
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
val newCharges: Charge array
val balance: int
module Array
from Microsoft.FSharp.Collections
val mapFoldBack: mapping: ('T -> 'State -> 'Result * 'State) -> array: 'T array -> state: 'State -> 'Result array * 'State
val charge: Charge
val acc: int
val i: int
val o: int
Evaluates newCharges to [|In 2; Out 4; In 6|] and balance to 2 .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val mapi: mapping: (int -> 'T -> 'U) -> array: 'T array -> 'U array
val i: int
val x: int
Evaluates to [| 10; 11; 12 |]
|
||||||
Full Usage:
Array.mapi2 mapping array1 array2
Parameters:
int -> 'T1 -> 'T2 -> 'U
-
The function to transform pairs of input elements and their indices.
array1 : 'T1 array
-
The first input array.
array2 : 'T2 array
-
The second input array.
Returns: 'U array
The array of transformed elements.
|
Example
val inputs1: string array
val inputs2: int array
module Array
from Microsoft.FSharp.Collections
val mapi2: mapping: (int -> 'T1 -> 'T2 -> 'U) -> array1: 'T1 array -> array2: 'T2 array -> 'U array
val i: int
val x: string
val y: int
Evaluates to [|(0, 'a'); (1, 'd'); (2, 'o')|]
|
||||||
Full Usage:
Array.max array
Parameters:
'T array
-
The input array.
Returns: 'T
The maximum element.
Modifiers: inline Type parameters: 'T |
Throws ArgumentException for empty arrays.
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val max: array: 'T array -> 'T (requires comparison)
Evaluates to 12
Example
val inputs: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val max: array: 'T array -> 'T (requires comparison)
Throws System.ArgumentException .
|
||||||
Full Usage:
Array.maxBy projection array
Parameters:
'T -> 'U
-
The function to transform the elements into a type supporting comparison.
array : 'T array
-
The input array.
Returns: 'T
The maximum element.
Modifiers: inline Type parameters: 'T, 'U |
Throws ArgumentException for empty arrays.
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val maxBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to "cccc"
Example
val inputs: string array
Multiple items
val string: value: 'T -> string -------------------- type string = System.String type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val maxBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Throws System.ArgumentException .
|
||||||
Full Usage:
Array.min array
Parameters:
'T array
-
The input array.
Returns: 'T
The minimum element.
Modifiers: inline Type parameters: 'T |
Throws ArgumentException for empty arrays
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val min: array: 'T array -> 'T (requires comparison)
Evaluates to 10
Example
val inputs: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val min: array: 'T array -> 'T (requires comparison)
Throws System.ArgumentException .
|
||||||
Full Usage:
Array.minBy projection array
Parameters:
'T -> 'U
-
The function to transform the elements into a type supporting comparison.
array : 'T array
-
The input array.
Returns: 'T
The minimum element.
Modifiers: inline Type parameters: 'T, 'U |
Throws ArgumentException for empty arrays.
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val minBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to "b"
Example
val inputs: string array
Multiple items
val string: value: 'T -> string -------------------- type string = System.String type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val minBy: projection: ('T -> 'U) -> array: 'T array -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Throws System.ArgumentException .
|
||||||
|
|||||||
|
Example
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq -------------------- type 'T seq = System.Collections.Generic.IEnumerable<'T> module Array
from Microsoft.FSharp.Collections
val ofSeq: source: 'T seq -> 'T array
Evaluates to [| 1; 2; 5 |] .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val pairwise: array: 'T array -> ('T * 'T) array
Evaluates to [|(1, 2); (2, 3); (3, 4)|] .
|
||||||
Full Usage:
Array.partition predicate array
Parameters:
'T -> bool
-
The function to test the input elements.
array : 'T array
-
The input array.
Returns: 'T array * 'T array
A pair of arrays. The first containing the elements the predicate evaluated to true,
and the second containing those evaluated to false.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val partition: predicate: ('T -> bool) -> array: 'T array -> 'T array * 'T array
val x: int
Evaluates to ([|2; 4|], [|1; 3|]) .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val permute: indexMap: (int -> int) -> array: 'T array -> 'T array
val x: int
Evaluates to [|4; 1; 2; 3|] .
|
||||||
|
Applies the given function to successive elements, returning the first
result where the function returns
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val pick: chooser: ('T -> 'U option) -> array: 'T array -> 'U
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Evaluates to "2" .
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val pick: chooser: ('T -> 'U option) -> array: 'T array -> 'U
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Throws KeyNotFoundException .
|
||||||
Full Usage:
Array.reduce reduction array
Parameters:
'T -> 'T -> 'T
-
The function to reduce a pair of elements to a single element.
array : 'T array
-
The input array.
Returns: 'T
The final result of the reductions.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val reduce: reduction: ('T -> 'T -> 'T) -> array: 'T array -> 'T
val a: int
val b: int
Evaluates to 1342 , by computing ((1 * 10 + 3) * 10 + 4) * 10 + 2
|
||||||
Full Usage:
Array.reduceBack reduction array
Parameters:
'T -> 'T -> 'T
-
A function that takes in the next-to-last element of the list and the
current accumulated result to produce the next accumulated result.
array : 'T array
-
The input array.
Returns: 'T
The final result of the reductions.
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val reduceBack: reduction: ('T -> 'T -> 'T) -> array: 'T array -> 'T
val a: int
val b: int
Evaluates to 2431 , by computing 1 + (3 + (4 + 2 * 10) * 10) * 10
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val removeAt: index: int -> source: 'T array -> 'T array
Evaluates to [| 0; 2 |] .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val removeManyAt: index: int -> count: int -> source: 'T array -> 'T array
Evaluates to [| 0; 3 |] .
|
||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val replicate: count: int -> initial: 'T -> 'T array
Evaluates to [| "a"; "a"; "a" |] .
|
||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val rev: array: 'T array -> 'T array
Evaluates to [| 2; 1; 0 |] .
|
||||||
|
ExampleApply a list charges and collect the running balances as each is applied:
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge array
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
module Array
from Microsoft.FSharp.Collections
val scan<'T,'State> : folder: ('State -> 'T -> 'State) -> state: 'State -> array: 'T array -> 'State array
val acc: int
val charge: Charge
val i: int
val o: int
Evaluates to [|0; 1; -1; 2|] . Note 0 is the intial
state, 1 the next state, -1 the next state, and 2 the final state.
|
||||||
|
ExampleApply a list charges from back to front, and collect the running balances as each is applied:
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge array
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
module Array
from Microsoft.FSharp.Collections
val scanBack: folder: ('T -> 'State -> 'State) -> array: 'T array -> state: 'State -> 'State array
val charge: Charge
val acc: int
val i: int
val o: int
Evaluates to [|2; 1; 3; 0|] by processing each input from back to front. Note 0 is the intial
state, 3 the next state, 1 the next state, and 2 the final state.
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val set: array: 'T array -> index: int -> value: 'T -> unit
After evaluation inputs contains [| "a"; "B"; "c" |]
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val set: array: 'T array -> index: int -> value: 'T -> unit
Throws IndexOutOfRangeException
|
||||||
Full Usage:
Array.singleton value
Parameters:
'T
-
The input item.
Returns: 'T array
The result array of one item.
Modifiers: inline Type parameters: 'T |
Example
module Array
from Microsoft.FSharp.Collections
val singleton: value: 'T -> 'T array
Evaluates to [| 7 |] .
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val skip: count: int -> array: 'T array -> 'T array
Evaluates to [| "c"; "d" |]
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val skip: count: int -> array: 'T array -> 'T array
Throws ArgumentException .
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val skip: count: int -> array: 'T array -> 'T array
Evaluates to [| "a"; "b"; "c"; "d" |] .
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val skipWhile: predicate: ('T -> bool) -> array: 'T array -> 'T array
val x: string
property System.String.Length: int with get
Evaluates to [|"bbb"; "cc"; "d"|]
|
||||||
|
Sorts the elements of an array, returning a new array. Elements are compared using Operators.compare. This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val sort: array: 'T array -> 'T array (requires comparison)
Evaluates to [| 1; 1; 3; 4; 6; 8 |] .
|
||||||
|
Sorts the elements of an array, using the given projection for the keys and returning a new array. Elements are compared using Operators.compare. This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.
Example
val input: string array
module Array
from Microsoft.FSharp.Collections
val sortBy: projection: ('T -> 'Key) -> array: 'T array -> 'T array (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to [|"a"; "dd"; "bbb"; "cccc"|] .
|
||||||
|
Sorts the elements of an array, in descending order, using the given projection for the keys and returning a new array. Elements are compared using Operators.compare. This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.
Example
val input: string array
module Array
from Microsoft.FSharp.Collections
val sortByDescending: projection: ('T -> 'Key) -> array: 'T array -> 'T array (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to [|"cccc"; "bbb"; "dd"; "a"|] .
|
||||||
|
Sorts the elements of an array, in descending order, returning a new array. Elements are compared using Operators.compare. This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val sortDescending: array: 'T array -> 'T array (requires comparison)
Evaluates to [| 8; 6; 4; 3; 1; 1 |] .
|
||||||
|
Sorts the elements of an array by mutating the array in-place, using the given comparison function. Elements are compared using Operators.compare.
Example
Multiple items
val array: int array -------------------- type 'T array = 'T array module Array
from Microsoft.FSharp.Collections
val sortInPlace: array: 'T array -> unit (requires comparison)
After evaluation array contains [| 1; 1; 3; 4; 6; 8 |] .
|
||||||
Full Usage:
Array.sortInPlaceBy projection array
Parameters:
'T -> 'Key
-
The function to transform array elements into the type that is compared.
array : 'T array
-
The input array.
|
Sorts the elements of an array by mutating the array in-place, using the given projection for the keys. Elements are compared using Operators.compare. This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.
Example
Multiple items
val array: string array -------------------- type 'T array = 'T array module Array
from Microsoft.FSharp.Collections
val sortInPlaceBy: projection: ('T -> 'Key) -> array: 'T array -> unit (requires comparison)
val s: string
property System.String.Length: int with get
After evaluation array contains [|"a"; "dd"; "bbb"; "cccc"|] .
|
||||||
|
ExampleThe following sorts entries using a comparison function that compares string lengths then index numbers:
val compareEntries: n1: int * s1: string -> n2: int * s2: string -> int
val n1: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val s1: string
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val n2: int
val s2: string
val c: int
val compare: e1: 'T -> e2: 'T -> int (requires comparison)
property System.String.Length: int with get
Multiple items
val array: (int * string) array -------------------- type 'T array = 'T array module Array
from Microsoft.FSharp.Collections
val sortInPlaceWith: comparer: ('T -> 'T -> int) -> array: 'T array -> unit
After evaluation array contains [|(0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb")|] .
|
||||||
|
This is not a stable sort, i.e. the original order of equal elements is not necessarily preserved. For a stable sort, consider using Seq.Sort.
ExampleSort an array of pairs using a comparison function that compares string lengths then index numbers:
val compareEntries: n1: int * s1: string -> n2: int * s2: string -> int
val n1: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val s1: string
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val n2: int
val s2: string
val c: int
val compare: e1: 'T -> e2: 'T -> int (requires comparison)
property System.String.Length: int with get
val input: (int * string) array
module Array
from Microsoft.FSharp.Collections
val sortWith: comparer: ('T -> 'T -> int) -> array: 'T array -> 'T array
Evaluates to [|(0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb")|] .
|
||||||
|
Example
val input: int array
val front: int array
val back: int array
module Array
from Microsoft.FSharp.Collections
val splitAt: index: int -> array: 'T array -> 'T array * 'T array
Evaluates front to [|8; 4; 3|] and back to [|1; 6; 1|] .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val splitInto: count: int -> array: 'T array -> 'T array array
Evaluates to seq [| [|1; 2|]; [|3; 4|]; [|5|] |]
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val splitInto: count: int -> array: 'T array -> 'T array array
Throws ArgumentException
|
||||||
|
Slicing syntax is generally preferred, e.g.
val input: int array
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val sub: array: 'T array -> startIndex: int -> count: int -> 'T array
Evaluates to [| 2; 3; 4 |] .
|
||||||
Full Usage:
Array.sum array
Parameters:
^T array
-
The input array.
Returns: ^T
The resulting sum.
Modifiers: inline Type parameters: ^T |
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val sum: array: 'T array -> 'T (requires member (+) and member Zero)
Evaluates to 11 .
|
||||||
Full Usage:
Array.sumBy projection array
Parameters:
'T -> ^U
-
The function to transform the array elements into the type to be summed.
array : 'T array
-
The input array.
Returns: ^U
The resulting sum.
Modifiers: inline Type parameters: 'T, ^U |
Example
val input: string array
module Array
from Microsoft.FSharp.Collections
val sumBy: projection: ('T -> 'U) -> array: 'T array -> 'U (requires member (+) and member Zero)
val s: string
property System.String.Length: int with get
Evaluates to 7 .
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tail: array: 'T array -> 'T array
Evaluates to [| "bb"; "ccc" |]
|
||||||
|
Throws
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val take: count: int -> array: 'T array -> 'T array
Evaluates to [| "a"; "b" |]
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val take: count: int -> array: 'T array -> 'T array
Throws InvalidOperationException .
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val take: count: int -> array: 'T array -> 'T array
Evaluates to [| |] .
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val takeWhile: predicate: ('T -> bool) -> array: 'T array -> 'T array
val x: string
property System.String.Length: int with get
Evaluates to [| "a"; "bb" |]
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val toList: array: 'T array -> 'T list
Evaluates to [ 1; 2; 5 ] .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val toSeq: array: 'T array -> 'T seq
Evaluates to seq { 1; 2; 5 } .
|
||||||
|
Example
val inputs: int array array
module Array
from Microsoft.FSharp.Collections
val transpose: arrays: 'T array seq -> 'T array array
Evaluates to [|[|10; 11|]; [|20; 21|]; [|30; 31|]|] .
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val truncate: count: int -> array: 'T array -> 'T array
Evaluates to [| "a"; "b" |]
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val truncate: count: int -> array: 'T array -> 'T array
Evaluates to [| "a"; "b"; "c"; "d" |]
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val truncate: count: int -> array: 'T array -> 'T array
Evaluates to [| |] .
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tryExactlyOne: array: 'T array -> 'T option
Evaluates to Some banana
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tryExactlyOne: array: 'T array -> 'T option
Evaluates to None
Example
val inputs: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val tryExactlyOne: array: 'T array -> 'T option
Evaluates to None
|
||||||
|
ExampleTry to find the first even number:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFind: predicate: ('T -> bool) -> array: 'T array -> 'T option
val elm: int
Evaluates to Some 2
ExampleTry to find the first even number:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFind: predicate: ('T -> bool) -> array: 'T array -> 'T option
val elm: int
Evaluates to None
|
||||||
|
ExampleTry to find the first even number from the back:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindBack: predicate: ('T -> bool) -> array: 'T array -> 'T option
val elm: int
Evaluates to Some 4
ExampleTry to find the first even number from the back:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindBack: predicate: ('T -> bool) -> array: 'T array -> 'T option
val elm: int
Evaluates to None
|
||||||
|
ExampleTry to find the index of the first even number:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindIndex: predicate: ('T -> bool) -> array: 'T array -> int option
val elm: int
Evaluates to Some 1
ExampleTry to find the index of the first even number:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindIndex: predicate: ('T -> bool) -> array: 'T array -> int option
val elm: int
Evaluates to None
|
||||||
|
ExampleTry to find the index of the first even number from the back:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindIndexBack: predicate: ('T -> bool) -> array: 'T array -> int option
val elm: int
Evaluates to Some 3
ExampleTry to find the index of the first even number from the back:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val tryFindIndexBack: predicate: ('T -> bool) -> array: 'T array -> int option
val elm: int
Evaluates to None
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tryHead: array: 'T array -> 'T option
Evaluates to Some "banana"
Example
val inputs: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val tryHead: array: 'T array -> 'T option
Evaluates to None
|
||||||
|
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tryItem: index: int -> array: 'T array -> 'T option
Evaluates to Some "b" .
Example
val inputs: string array
module Array
from Microsoft.FSharp.Collections
val tryItem: index: int -> array: 'T array -> 'T option
Evaluates to None .
|
||||||
|
Example
module Array
from Microsoft.FSharp.Collections
val tryLast: array: 'T array -> 'T option
Evaluates to Some "banana"
Example
module Array
from Microsoft.FSharp.Collections
val tryLast: array: 'T array -> 'T option
Evaluates to None
|
||||||
|
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val tryPick: chooser: ('T -> 'U option) -> array: 'T array -> 'U option
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Evaluates to Some "2" .
Example
val input: int array
module Array
from Microsoft.FSharp.Collections
val tryPick: chooser: ('T -> 'U option) -> array: 'T array -> 'U option
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Evaluates to None .
|
||||||
Full Usage:
Array.unfold generator state
Parameters:
'State -> ('T * 'State) option
-
A function that takes in the current state and returns an option tuple of the next
element of the array and the next state value.
state : 'State
-
The initial state value.
Returns: 'T array
The result array.
|
Example
module Array
from Microsoft.FSharp.Collections
val unfold<'T,'State> : generator: ('State -> ('T * 'State) option) -> state: 'State -> 'T array
val state: int
union case Option.None: Option<'T>
union case Option.Some: Value: 'T -> Option<'T>
Evaluates to [| 1; 2; 4; 8; 16; 32; 64 |]
|
||||||
|
Example
val inputs: (int * string) array
val numbers: int array
val names: string array
module Array
from Microsoft.FSharp.Collections
val unzip: array: ('T1 * 'T2) array -> 'T1 array * 'T2 array
Evaluates numbers to [|1; 2|] and names to [|"one"; "two"|] .
|
||||||
|
Example
val inputs: (int * string * string) array
val numbers: int array
val names: string array
val roman: string array
module Array
from Microsoft.FSharp.Collections
val unzip3: array: ('T1 * 'T2 * 'T3) array -> 'T1 array * 'T2 array * 'T3 array
Evaluates numbers to [|1; 2|] , names to [|"one"; "two"|] and roman to [|"I"; "II"|] .
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val updateAt: index: int -> value: 'T -> source: 'T array -> 'T array
Evaluates to [| 0; 9; 2 |] .
|
||||||
|
This is identical to
ExampleSelect only the even numbers:
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val where: predicate: ('T -> bool) -> array: 'T array -> 'T array
val elm: int
Evaluates to [| 2; 4 |]
|
||||||
|
Example
val inputs: int array
module Array
from Microsoft.FSharp.Collections
val windowed: windowSize: int -> array: 'T array -> 'T array array
Evaluates to [|[|1; 2; 3|]; [|2; 3; 4|]; [|3; 4; 5|]|]
|
||||||
|
Example
val arr: int array
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T array = 'T array
module Array
from Microsoft.FSharp.Collections
val zeroCreate: count: int -> 'T array
Evaluates to [| 0; 0; 0; 0 |]
|
||||||
|
Example
val numbers: int array
val names: string array
module Array
from Microsoft.FSharp.Collections
val zip: array1: 'T1 array -> array2: 'T2 array -> ('T1 * 'T2) array
Evaluates to [| (1, "one"); (2, "two") |] .
|
||||||
|
Example
val numbers: int array
val names: string array
val roman: string array
module Array
from Microsoft.FSharp.Collections
val zip3: array1: 'T1 array -> array2: 'T2 array -> array3: 'T3 array -> ('T1 * 'T2 * 'T3) array
Evaluates to [|(1, "one", "I"); (2, "two", "II")|] .
|