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

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

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

Tests if any pair of corresponding elements of the lists satisfies the given predicate. The lists must have equal lengths.

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


predicate Type: 'T1 -> 'T2 ->bool

The function to test the input elements.

list1 Type: 'T1list

The first input list.

list2 Type: 'T2list

The second input list.

Return Value

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


ArgumentExceptionThrown when the input lists differ in length.


The predicate is applied to matching elements in the two 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 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