List flattening in F#

f#

Solution

Try the following

let regEntries = 
    ["SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
     "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"]
    |> Seq.collect (fun p ->
       let k = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(p)
       k.GetSubKeyNames()
       |> Seq.map (fun x -> k.OpenSubKey(x)) 
       |> Seq.filter (fun x -> x.GetValue("ProductId") <> null)))
    |> List.ofSeq

The `Seq.concat` method is useful for converting a `T list list` to a `T list`. Note that I switched a lot of your `List.` calls to `Seq.` calls. There didn't seem to be any need to create an actual `list` until the very end hence I kept it as a simple `seq`

Problem

I'm new to F# and trying to rewrite one of our applications in F# to try and learn it along the way and I am having a bit of trouble flattening a list. I have searched and found several answers, but I can't seem to get any of them to work. My data type is saying it is val regEntries: RegistryKey list list I would like it to only be one list. Below is my code: ``` namespace DataModule module RegistryModule = open Microsoft.Win32 let regEntries = ["SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"] |> List.map (fun x -> Microsoft.Win32.Registry.LocalMachine.OpenSubKey(x)) |> List.map (fun k -> List.ofArray (k.GetSubKeyNames()) |> List.map (fun x -> k.OpenSubKey(x)) |> List.filter (fun x -> x.GetValue("ProductId") <> null)) ```

Original source

Related problems