I am relative new with F# and one of the more complicate things to me is how to use yield properly. I am trying to generate a sequence by reading a text file and extracting for each line the values with a and add them into a sequence(the result)
regexp function from http://www.fssnip.net/29/title/Regular-expression-active-pattern
let (|Regex|_|) pattern input =
let m = Regex.Match(input, pattern)
if m.Success then Some(List.tail [ for g in m.Groups -> g.Value ])
else None
let extractCoordinates input =
match input with
| Regex @"\(([0-9]{3})\)[-. ]?([0-9]{3})[-. ]?([0-9]{4})" [ area; prefix; suffix ] ->
[ area; prefix; suffix ]
| _ -> []
read file and generate sequence
open System.IO
let filepath = __SOURCE_DIRECTORY__ + @"../../test_input_01.txt"
let values =
File.ReadAllLines
|> Seq.map (fun l -> extractCoordinates l)
but it is no working
error FS0001: The type 'string -> string []' is not compatible with the type 'seq<'a>'
Could anyone tell me how to apply a function to each element of a list and store the output into a sequence result? Using yield or not...