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

根据泛型哈希和项的相等性比较,返回不包含重复项的序列。 如果某个元素在序列中出现多次,则后面出现的该元素将被丢弃。

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

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

// Signature:
Seq.distinct : seq<'T> -> seq<'T> (requires equality)

// Usage:
Seq.distinct source

参数

  • source
    类型:seq<'T>

    输入序列。

异常

异常

Condition

ArgumentNullException

在输入序列为 null 时引发。

返回值

结果序列。

备注

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

示例

下面的示例说明 Seq.distinct 的用法。 此示例生成一系列数的二进制表示形式。 然后,确定唯一编号为 0 和 1。

let binary n =
    let rec generateBinary n =
        if (n / 2 = 0) then [n]
        else (n % 2) :: generateBinary (n / 2)
    generateBinary n |> List.rev |> Seq.ofList

printfn "%A" (binary 1024)

let resultSequence = Seq.distinct (binary 1024)
printfn "%A" resultSequence
  

平台

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

版本信息

F#核心库版本

支持:2.0,4.0,可移植

请参见

参考

Collections.Seq 模块 (F#)

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