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

更新:2010 年 8 月

测试从两个序列提取的所有元素对是否都满足给定谓词。 如果一个序列比另一个序列短,则会忽略较长序列的其余元素。

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

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

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

// Usage:
Seq.forall2 predicate source1 source2

参数

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

    用于测试输入序列中的元素对的函数。

  • source1
    类型:seq<'T1>

    第一个输入序列。

  • source2
    类型:seq<'T2>

    第二个输入序列。

异常

异常

Condition

ArgumentNullException

在任一输入序列为 null 时引发。

返回值

如果序列中的所有元素对都满足给定谓词,则为 true。 否则,返回 false。

备注

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

示例

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

// This function can be used on any sequence, so the same function
// works with both lists and arrays.
let allEqual = Seq.forall2 (fun elem1 elem2 -> elem1 = elem2)
printfn "%A" (allEqual [| 1; 2 |] [| 1; 2 |])
printfn "%A" (allEqual [ 1; 2 ] [ 2; 1 ])

Output

  

平台

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# 运行时

受以下版本支持:2.0、4.0

Silverlight

受以下版本支持:3

请参见

参考

Collections.Seq 模块 (F#)

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

修订记录

Date

修订记录

原因

2010 年 8 月

添加了代码示例。

信息补充。