Seq.collect<'T,'Collection,'U> 函数 (F#)

将给定函数应用于序列的每个元素并将所有结果串联在一起。

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

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

// Signature:
Seq.collect : ('T -> 'Collection) -> seq<'T> -> seq<'U> (requires 'Collection :> seq<'U>)

// Usage:
Seq.collect mapping source

参数

  • mapping
    类型:'T -> 'Collection

    一个函数,用于将输入序列的元素转换为序列,这些序列随后串连在一起。

  • source
    类型:seq<'T>

    输入序列。

异常

异常

Condition

ArgumentNullException

在输入序列为 null 时引发。

返回值

结果序列。

备注

对序列进行惰性的计算。 因此,结果将延迟到枚举后。

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

示例

下面的代码演示了 Seq.collect 的用法。

let addNegations seq1 =
   Seq.collect (fun x -> seq { yield x; yield -x }) seq1
   |> Seq.sort
addNegations [ 1 .. 4 ] |> Seq.iter (fun elem -> printf "%d " elem)
printfn ""
addNegations [| 0; -4; 2; -12 |] |> Seq.iter (fun elem -> printf "%d " elem)

Output

  

平台

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

版本信息

F#核心库版本

支持:2.0,4.0,可移植

请参见

参考

Collections.Seq 模块 (F#)

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