List.iteri2<'T1,'T2> Function (F#)
Updated: May 2010
Applies the given function to two collections simultaneously. The collections must have identical size. The integer passed to the function indicates the index of element.
Namespace/Module Path: Microsoft.FSharp.Collections.List
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature: List.iteri2 : (int -> 'T1 -> 'T2 -> unit) -> 'T1 list -> 'T2 list -> unit // Usage: List.iteri2 action list1 list2
The following code example illustrates the use of List.iteri2 and compares its behavior with related functions.
let list1 = [1; 2; 3] let list2 = [4; 5; 6] List.iter (fun x -> printfn "List.iter: element is %d" x) list1 List.iteri(fun i x -> printfn "List.iteri: element %d is %d" i x) list1 List.iter2 (fun x y -> printfn "List.iter2: elements are %d %d" x y) list1 list2 List.iteri2 (fun i x y -> printfn "List.iteri2: element %d of list1 is %d element %d of list2 is %d" i x i y) list1 list2
Output
List.iter: element is 1 List.iter: element is 2 List.iter: element is 3 List.iteri: element 0 is 1 List.iteri: element 1 is 2 List.iteri: element 2 is 3 List.iter2: elements are 1 4 List.iter2: elements are 2 5 List.iter2: elements are 3 6 List.iteri2: element 0 of list1 is 1 element 0 of list2 is 4 List.iteri2: element 1 of list1 is 2 element 1 of list2 is 5 List.iteri2: element 2 of list1 is 3 element 2 of list2 is 6