Seq.exists2<'T1,'T2> 函数 (F#)

测试输入序列的任何对应元素对是否都满足给定谓词。

命名空间/模块路径: Microsoft.FSharp.Collections.Seq

程序集:FSharp.Core(在 FSharp.Core.dll 中)

// Signature:
Seq.exists2 : ('T1 -> 'T2 -> bool) -> seq<'T1> -> seq<'T2> -> bool

// Usage:
Seq.exists2 predicate source1 source2

参数

  • predicate
    类型:'T1 -> 'T2 -> bool

    用于测试输入序列中的每对项的函数。

  • source1
    类型:seq<'T1>

    第一个输入序列。

  • source2
    类型:seq<'T2>

    第二个输入序列。

异常

异常

Condition

ArgumentNullException

在两个输入序列中的任一一个为 null 时引发。

返回值

谓词将应用来对两个序列中的元素进行匹配,直至达到两个集合长度中较小的长度为止。 如果任何应用程序返回 true,则总体结果为 true,并且不再测试其他元素。 否则将返回 false。

备注

如果一个序列比另一个序列短,则会忽略较长序列的其余元素。

此函数在编译的程序集中名为 Exists2。 如果从 F# 以外的语言中访问函数,或通过反射访问成员,请使用此名称。

示例

下面的代码示例演示如何使用 Seq.exists2

// Use Seq.exists2 to compare elements in two sequences.
// isEqualElement returns true if any elements at the same position in two supplied
// sequences match.
let isEqualElement seq1 seq2 = Seq.exists2 (fun elem1 elem2 -> elem1 = elem2) seq1 seq2
let seq1to5 = seq { 1 .. 5 }
let seq5to1 = seq { 5 .. -1 .. 1 }
if (isEqualElement seq1to5 seq5to1) then
    printfn "Sequences %A and %A have at least one equal element at the same position." seq1to5 seq5to1
else
    printfn "Sequences %A and %A do not have any equal elements that are at the same position." seq1to5 seq5to1

Output

  

平台

Windows 8,Windows 7,Windows server 2012中,Windows server 2008 R2

版本信息

F#核心库版本

支持:2.0,4.0,可移植

请参见

参考

Collections.Seq 模块 (F#)

Microsoft.FSharp.Collections 命名空间 (F#)