comparison tests/reddit.ur @ 23:e1e451cf85bb

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