annotate tests/reddit.ur @ 22:923e097e9ba3

Simplify Reddit example
author Adam Chlipala <adam@chlipala.net>
date Sat, 29 Sep 2012 10:32:44 -0400
parents 7275f59cab61
children e1e451cf85bb
rev   line source
adam@21 1 fun main () =
adam@21 2 doc <- Feed.fetch "http://www.reddit.com/?limit=30";
adam@21 3
adam@21 4 acc <- Feed.app' (Feed.tree (Feed.tagAOR "div" {DataUps = "data-ups", Class = "class"} {Style = "style"})
adam@22 5 (Feed.tagAOR "a" {Href = "href", Class = "class"} {Style = "style"}))
adam@21 6 (fn (div, a) (count, list) =>
adam@22 7 return (if count >= 30
adam@22 8 || not (String.isPrefix {Full = div.Class, Prefix = " thing "})
adam@22 9 || Option.isSome (String.sindex {Haystack = div.Class, Needle = "promoted"})
adam@22 10 || div.Style = Some "display:none"
adam@22 11 || a.Class <> "title "
adam@22 12 || a.Style = Some "display:none" then
adam@22 13 (count, list)
adam@22 14 else
adam@22 15 (count + 1, a.Href :: list)))
adam@21 16 doc (0, []);
adam@21 17
adam@21 18 return <xml><body>
adam@21 19 <h1>Top 30 Reddit Links</h1>
adam@21 20
adam@21 21 <ol>
adam@21 22 {List.mapX (fn url => <xml><li>{[url]}</li></xml>) (List.rev acc.2)}
adam@21 23 </ol>
adam@21 24 </body></xml>