Expand Minimize
This topic has not yet been rated - Rate this topic

Array.mapi2<'T1,'T2,'U> Function (F#)

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 ArgumentException is raised.

Namespace/Module Path: Microsoft.FSharp.Collections.Array

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

// Signature:
Array.mapi2 : (int -> 'T1 -> 'T2 -> 'U) -> 'T1 [] -> 'T2 [] -> 'U []

// Usage:
Array.mapi2 mapping array1 array2
mapping

Type: int -> 'T1 -> 'T2 -> 'U

The function to transform pairs of input elements and their indices.

array1

Type: 'T1 []

The first input array.

array2

Type: 'T2 []

The second input array.

Exception

Condition

ArgumentException

Thrown when the input arrays differ in length.

The array of transformed elements.

This function is named MapIndexed2 in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

The following code demonstrates the use of Array.mapi2.

let array1 = [| 1; 2; 3 |]
let array2 = [| 4; 5; 6 |]
let arrayAddTimesIndex = Array.mapi2 (fun i x y -> (x + y) * i) array1 array2
printfn "%A" arrayAddTimesIndex

Output

[|0; 7; 18|]

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.