Seq.exists<'T> 函数 (F#)
更新:2010 年 8 月
测试序列中是否有任何元素满足给定谓词。
命名空间/模块路径:Microsoft.FSharp.Collections.Seq
程序集:FSharp.Core(在 FSharp.Core.dll 中)
// Signature:
Seq.exists : ('T -> bool) -> seq<'T> -> bool
// Usage:
Seq.exists predicate source
参数
异常
异常 |
Condition |
---|---|
在输入序列为 null 时引发。 |
返回值
谓词应用于输入序列的元素。 如果任何应用程序返回 true,则总体结果为 true,并且不再测试其他元素。 否则,返回 false。
备注
此函数在编译的程序集中名为 Exists。 如果从 F# 以外的语言中访问函数,或通过反射访问成员,请使用此名称。
示例
下面的代码演示如何使用 Seq.exists。
// Use Seq.exists to determine whether there is an element of a sequence
// that satisfies a given Boolean expression.
// containsNumber returns true if any of the elements of the supplied sequence match
// the supplied number.
let containsNumber number seq1 = Seq.exists (fun elem -> elem = number) seq1
let seq0to3 = seq {0 .. 3}
printfn "For sequence %A, contains zero is %b" seq0to3 (containsNumber 0 seq0to3)
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
请参见
参考
Microsoft.FSharp.Collections 命名空间 (F#)
修订记录
Date |
修订记录 |
原因 |
---|---|---|
2010 年 8 月 |
添加了代码示例。 |
信息补充。 |