Last active
December 15, 2015 07:29
-
-
Save vasily-kirichenko/5223371 to your computer and use it in GitHub Desktop.
FSharp.Data XML Type Provider vs FSharpx one
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
open FSharp.Data | |
open FSharpx | |
[<Literal>] | |
let xml = """<?xml version="1.0" encoding="utf-8"?> | |
<response list="true"> | |
<count>7</count> | |
<message> | |
<body>Hello!</body> | |
<mid>10850</mid> | |
<from_id>62912577</from_id> | |
<date>1268215527</date> | |
<read_state>0</read_state> | |
<out>1</out> | |
</message> | |
<message> | |
<body>Hello!!</body> | |
<mid>10848</mid> | |
<from_id>5005272</from_id> | |
<date>1268215303</date> | |
<read_state>1</read_state> | |
<out>0</out> | |
</message> | |
</response>""" | |
// FSharp.Data | |
type Xml = XmlProvider<xml> | |
let sample = Xml.GetSample().GetMessages() | |
|> Seq.map (fun msg -> msg.Body, msg.Date) // beautiful! | |
|> Seq.toList | |
// FSharpx | |
type Xmlx = StructuredXml<Schema = xml> | |
let samplex = Xmlx().Root.GetMessages() | |
|> Seq.map (fun msg -> (msg.GetBodies() |> Seq.head).Element.Value, // this is just ugly | |
(msg.GetDates() |> Seq.head).Element.Value) // and there're no types at all... | |
|> Seq.toList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment