To fix the problem in the original approach, you need to use Seq.append instead of Seq.concat . The initial value for fold should be an empty sequence, which can be written as Seq.empty :
let res = files |> Seq.fold(fun x item -> let lines = FileEnumerator(item) let sq = Seq.append x lines sq ) Seq.empty
If you want to use Seq.concat , you need to write Seq.concat [x; lines] Seq.concat [x; lines] because concat expects a sequence of concatenated sequences. On the other hand, append just takes two sequences, so it's easier to use.
Another (simpler) way to concatenate all strings is to use yield! in sequence expressions:
let res = seq { for item in files do yield! FileEnumerator(item) }
This creates a sequence by repeating all the files and adding all the lines from the files (in order) to the resulting sequence. yield! construct yield! Adds all elements of a sequence to the result.
source share