It's actually simpler if you process from the end with foldBack
, and in particular you don't need to reverse the result so it should be faster:
let processedLines =
(rawLines, ("", []))
||> List.foldBack (fun line (currentLine, allLines) ->
if line.StartsWith "Header:" then
"", line + currentLine :: allLines
else
line + currentLine, allLines)
|> function
| "", lines -> lines
| _ -> failwith "The original string didn't start with 'Header:'"