2015-11-02 65 views
2

如何連接字符串選項列表?F#連接字符串選項列表

let m = [ ""; "12"; "a"; "b"] 
// I can join these with 
m |> List.toSeq |> String.concat "\n" 

// now I got a list of string option list 
let l = [Some ""; None; Some "a"; Some "b"] 
l |> List.toSeq |> ???? 

回答

8

您第一次使用List.choose爲「提取」列表中的一些值:

l |> List.choose id |> String.concat "\n" 

注意你不需要List.toSeq爲SEQ是一個別名IEnumerable't list已經實現了它。