Seq.find<'T> 函数 (F#)

返回给定函数为其返回 true 的第一个元素。

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

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

// Signature:
Seq.find : ('T -> bool) -> seq<'T> -> 'T

// Usage:
Seq.find predicate source

参数

  • predicate
    类型:'T -> bool

    用于测试是否应返回序列中的某一项的函数。

  • source
    类型:seq<'T>

    输入序列。

异常

异常

Condition

ArgumentNullException

在输入序列为 null 时引发

KeyNotFoundException

用谓词进行计算时,如果没有元素返回 true,则引发此异常

返回值

返回给定函数为其返回 true 的第一个元素。

备注

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

示例

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

let isDivisibleBy number elem = elem % number = 0
let result = Seq.find (isDivisibleBy 5) [ 1 .. 100 ]
printfn "%d " result

Output

  

平台

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

版本信息

F#核心库版本

支持:2.0,4.0,可移植

请参见

参考

Collections.Seq 模块 (F#)

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