How does the map2 function handle uneven length lists?
e.g.
let list1 = [1; 2; 3]
let list2 = [4; 5; 6; 7]
let sumList = List.map2 (fun x y -> x + y) list1 list2
printfn "%A" sumList
It seems odd that this isn't mentioned in the documentation.
Even though the documentation doesn't cite it, one can easily check the source code to find out what happens and the implementation details.
As you can see in the link, when you pass a list of different size, invalidArg is called, throwing an ArgumentException with the message stored in the listsHadDifferentLengths resource.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With