Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

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

Tests if any pair of corresponding elements of the lists satisfies the given predicate.

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

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

// Signature:
List.exists2 : ('T1 -> 'T2 -> bool) -> 'T1 list -> 'T2 list -> bool

// Usage:
List.exists2 predicate list1 list2


Type: 'T1 -> 'T2 -> bool

The function to test the input elements.


Type: 'T1 list

The first input list.


Type: 'T2 list

The second input list.

true if any pair of elements satisfy the predicate. Otherwise, returns false.

The predicate is applied to matching elements in the two collections up to the lesser of the two lengths of the collections. If any application returns true then the overall result is true and no further elements are tested.

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

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

// Use List.exists2 to compare elements in two lists.
// isEqualElement returns true if any elements at the same position in two supplied
// lists match.
let isEqualElement list1 list2 = List.exists2 (fun elem1 elem2 -> elem1 = elem2) list1 list2
let list1to5 = [ 1 .. 5 ]
let list5to1 = [ 5 .. -1 .. 1 ]
if (isEqualElement list1to5 list5to1) then
    printfn "Lists %A and %A have at least one equal element at the same position." list1to5 list5to1
    printfn "Lists %A and %A do not have an equal element at the same position." list1to5 list5to1


Lists [1; 2; 3; 4; 5] and [5; 4; 3; 2; 1] have at least one equal element at the same position.

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

F# Runtime

Supported in: 2.0, 4.0


Supported in: 3

Community Additions

© 2015 Microsoft