Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# join string option list

Tags:

f#

How do I concatenate a list of string option?

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 |> ????
like image 963
salek Avatar asked Sep 17 '26 22:09

salek


1 Answers

you first use List.choose to "extract" the Some values of the list :

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

Note you don't need List.toSeq as seq is an alias for IEnumerable and 't list implement it already.

like image 103
Sehnsucht Avatar answered Sep 19 '26 20:09

Sehnsucht



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!