Created
November 1, 2015 21:29
-
-
Save DmitriyVlasov/45b03fc49d9a63f84d0a to your computer and use it in GitHub Desktop.
Пример использования провайдера типа CsvProvider из библиотеки FSharp.Data на примере получения таблицы медиа типов официально предоставляемых консорциумом IANA.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#I @"../../packages/FSharp.Data/lib/net40" | |
#r @"FSharp.Data.dll" | |
open FSharp.Data | |
[<Literal>] | |
let ianaCsvSample = "Name,Template,Reference | |
1d-interleaved-parityfec,application/1d-interleaved-parityfec,[RFC6015]" | |
type IanaMediaTypes = CsvProvider<ianaCsvSample> | |
let ianaMediaType = | |
["application"; "audio"; "image"; "message"; "model"; "multipart"; "text"; "video"; ] | |
|> Seq.map (fun fileName -> | |
fileName | |
|> sprintf "http://www.iana.org/assignments/media-types/%s.csv" | |
|> fun path -> IanaMediaTypes.Load(path) | |
|> fun csv -> csv.Rows |> Seq.map (fun row -> row.Name, row.Template)) | |
|> Seq.concat | |
|> Seq.cache | |
ianaMediaType | |
|> Seq.take 3 | |
|> Seq.iter (fun (name, template) -> printfn "%s%40s" name template ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment