Table of contents
Collapse the table of content
Expand the table of content

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

Den Delimarsky|Last Updated: 8/18/2017
3 Contributors

Creates a new list whose elements are the results of applying the given function to the corresponding elements of the two lists pairwise. The lists must have equal lengths.

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

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


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

// Usage:
List.map2 mapping list1 list2


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

The function to transform pairs of elements from the input lists.

list1 Type: 'T1list

The first input list.

list2 Type: 'T2list

The second input list.

Return Value

The list of resulting elements.


ArgumentExceptionThrown when the input lists differ in length.


The two lists list1 and list2 must have the same length. If they don't, an exception is thrown.

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


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


[5; 7; 9]


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

Collections.List Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft