F #: How to use a map with a collection (for example, regular expression matching)?

Soo ... F # no longer has IEnumerable.map_with_type ... this is how people matched collections. How can I do it?

let urlPat = "href\\s*=\\s*(?:(?:\\\"(?<url>[^\\\"]*)\\\")|(?<url>[^\\s]* ))";;
let urlRegex = new Regex(urlPat)
let matches = 
    urlRegex.Matches(http("http://www.google.com"))

let matchToUrl (urlMatch : Match) = urlMatch.Value
let urls = List.map matchToUrl matches

Thanks!

+5
source share
2 answers

you should write the last line as follows:

let urls = Seq.map matchToUrl (Seq.cast matches);;

And this can be written in a more convenient way using the pipelining operator:

let urls = matches|> Seq.cast |> Seq.map matchToUrl;;

F # automatically determines what the correct type of target is (because it knows what it looks like matchToUrl). This is only available for Seq, so you can use List.of_seqto get the data in the list again.

+12
source

User: Seq.cast What are you looking for?

+3
source

All Articles