다음을 통해 공유


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

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

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

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

// Signature:
Array.exists2 : ('T1 -> 'T2 -> bool) -> 'T1 [] -> 'T2 [] -> bool

// Usage:
Array.exists2 predicate array1 array2

Parameters

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

    The function to test the input elements.

  • array1
    Type: 'T1[]

    The first input array.

  • array2
    Type: 'T2[]

    The second input array.

Return Value

true if any result from predicate is true. Otherwise, false.

Remarks

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. Otherwise, if one collection is longer than the other then the ArgumentException exception is raised. Otherwise, false is returned.

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

Example

The following example shows the use Array.exists2 to test whether two arrays have at least one equal element.

let haveEqualElement = Array.exists2 (fun elem1 elem2 -> elem1 = elem2)
printfn "%A" (haveEqualElement [| 1; 2; 3 |] [| 3; 2; 1|])
true

Platforms

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

Reference

Collections.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)