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

predicate

Type: 'T1 -> 'T2 -> bool

The function to test the input elements.

list1

Type: 'T1 list

The first input list.

list2

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
else
    printfn "Lists %A and %A do not have an equal element at the same position." list1to5 list5to1

Output

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

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft