获取无效驱动器号的列表

Mas*_*low 1 f# sequences

let private GetDrives = seq{
let all=System.IO.DriveInfo.GetDrives()
for d in all do
    //if(d.IsReady && d.DriveType=System.IO.DriveType.Fixed) then
        yield d
}

let valid={'A'..'Z'}
let rec SearchRegistryForInvalidDrive (start:RegistryKey) = seq{
    let validDrives=GetDrives |> Seq.map (fun x -> x.Name.Substring(0,1))
    let invalidDrives= Seq.toList validDrives |> List.filter(fun x-> not (List.exists2 x b)) //(List.exists is the wrong method I think, but it doesn't compile
Run Code Online (Sandbox Code Playgroud)

我跟着F#:从另一个列表中筛选出一个列表中的项目但是无法将它应用于我的问题,因为我看到的解决方案似乎都没有编译.List.Contains不存在(缺少引用?)和ListA - ListB也不编译.

Dan*_*iel 7

open System.IO
let driveLetters = set [ for d in DriveInfo.GetDrives() -> d.Name.[0] ]
let unused = set ['A'..'Z'] - driveLetters
Run Code Online (Sandbox Code Playgroud)

  • @Maslow:`System.Collections.Generic.HashSet <>`,LINQ有许多类似集合的操作. (3认同)