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

返回一个进行枚举时最多返回 N 个元素的序列。

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

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

// Signature:
Seq.truncate : int -> seq<'T> -> seq<'T>

// Usage:
Seq.truncate count source

参数

  • count
    类型:int

    要枚举的项的最大数目。

  • source
    类型:seq<'T>

    输入序列。

异常

异常

Condition

ArgumentNullException

在输入序列为 null 时引发。

返回值

结果序列。

备注

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

示例

下面的代码示例演示 Seq.truncate 的用户,并将其行为与 Seq.take 进行比较。

let mySeq = seq { for i in 1 .. 10 -> i*i }
let truncatedSeq = Seq.truncate 5 mySeq
let takenSeq = Seq.take 5 mySeq

let truncatedSeq2 = Seq.truncate 20 mySeq
let takenSeq2 = Seq.take 20 mySeq

let printSeq seq1 = Seq.iter (printf "%A ") seq1; printfn ""

// Up to this point, the sequences are not evaluated.
// The following code causes the sequences to be evaluated.
truncatedSeq |> printSeq
truncatedSeq2 |> printSeq
takenSeq |> printSeq
// The following line produces a run-time error (in printSeq):
takenSeq2 |> printSeq
  

平台

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#)