Megosztás a következőn keresztül:


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

Like List.mapi, but mapping corresponding elements from two lists of equal length.

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

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

// Signature:
List.mapi2 : (int -> 'T1 -> 'T2 -> 'U) -> 'T1 list -> 'T2 list -> 'U list

// Usage:
List.mapi2 mapping list1 list2

Parameters

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

    The function to transform pairs of elements from the two lists and their index.

  • list1
    Type: 'T1list

    The first input list.

  • list2
    Type: 'T2list

    The second input list.

Return Value

The list of transformed elements.

Remarks

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.

Example

The following code example illustrates the use of List.mapi2.

let list1 = [1; 2; 3]
let list2 = [4; 5; 6]
let listAddTimesIndex = List.mapi2 (fun i x y -> (x + y) * i) list1 list2
printfn "%A" listAddTimesIndex

Output

[0; 7; 18]

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

Collections.List Module (F#)

Microsoft.FSharp.Collections Namespace (F#)