【Orcas】 Visual Studio 2007 【.NET3.0】
XLinqはVBの方が楽だね。(´・ω・)
Option Explicit On
Option Infer On
Option Strict On
Imports System
Imports System.Linq
Imports System.Xml.Linq
Module Test
Sub Main()
Dim rss = XDocument.Load("
http://www.microsoft.com/japan/msdn/rss.xml")
Dim q = _
From item In rss...<item> _
Order By CType(item.<pubDate>.Value, DateTime) Descending _
Select item.<title>.Value
For Each title in q.Take(5)
Console.WriteLine(title)
Next
End Sub
End Module
F#とLINQの相性ワロス。(´・ω・)
extension methodとcurryingの引数の順序が逆なので、いちいち変換しなければならん。
#I @"C:\WINDOWS\Microsoft.NET\Framework\v3.5.20209";;
#r "System.Core.dll";;
#r "System.Xml.Linq.dll";;
#light
open System
open System.Linq
open System.Xml.Linq
open IEnumerable
let to_XName s =
XName.op_Implicit(s)
let to_DateTime e =
XElement.op_Explicit(e) : DateTime
let to_Func f =
new Func<_, _>(f)
let order_by_desc f s =
Enumerable.OrderByDescending(s, to_Func f)
let select f s =
Enumerable.Select(s, to_Func f)
let take n s =
Enumerable.Take(s, n)
let _ =
let rss = XDocument.Load("
http://msdn.microsoft.com/rss.xml")
rss.Descendants(to_XName "item")
|> order_by_desc (fun e -> e.Element(to_XName "pubDate") |> to_DateTime)
|> select (fun e -> e.Element(to_XName "title").Value)
|> take 5
|> iter print_endline
関数合成を使った方がmonad風味が出るかな・・・。まあ、スレ違い気味だけど。
let _ =
XDocument.Load("
http://www.microsoft.com/japan/msdn/rss.xml")
|> ( fun d -> d.Descendants(to_XName "item")
>> order_by_desc (fun e -> e.Element(to_XName "pubDate") |> to_DateTime)
>> select (fun e -> e.Element(to_XName "title").Value)
>> take 5
>> iter print_endline )