{"id":717,"date":"2014-01-31T15:05:45","date_gmt":"2014-01-31T13:05:45","guid":{"rendered":"http:\/\/www.calvert.ch\/maurice\/?p=717"},"modified":"2015-02-22T21:30:43","modified_gmt":"2015-02-22T20:30:43","slug":"linqpad-is-even-better-than-i-thought","status":"publish","type":"post","link":"https:\/\/www.calvert.ch\/maurice\/2014\/01\/31\/linqpad-is-even-better-than-i-thought\/","title":{"rendered":"LINQPad is even better than I thought"},"content":{"rendered":"<p>I knew that <a title=\"LINQPad\" href=\"http:\/\/www.linqpad.net\/\">LINQPad<\/a> was good, but hadn&#8217;t realised that in addition to LINQ proper, one can write whole programs, complete with generics:<\/p>\n<pre class=\"nums:false lang:vbnet decode:true \">Function Rank(Of T As {IComparable(Of T)})(items As IEnumerable(Of T), item As T) As Integer\r\n\r\n   Dim ranked = From i In items\r\n                Order By i\r\n                Select New With {\r\n                   .key = i,\r\n                   .ranking = (From r In items\r\n                               Where r.CompareTo(i) &lt; 0).Count + 1}\r\n\r\n   Return (From i In ranked\r\n           Where i.key.CompareTo(item) = 0\r\n           Select i.ranking).Single\r\n\r\nEnd Function\r\n        \r\nSub Main()\r\n   Dim l As New list(Of Integer) From {9, 1, 3, 8, 4, 6}\r\n   Dim r As Integer = rank(Of Integer)(l, 6)\r\n   console.write(\"6 is the \" &amp; r &amp; \"th element of \")\r\n   For Each n As Integer In l.orderby(Function(x) x)\r\n       console.write(n &amp; \" \")\r\n   Next\r\n   console.writeline()\r\nEnd Sub\r\n<\/pre>\n<p>which correctly prints<br \/>\n<code>6 is the 4th element of<br \/>\n1 3 4 6 8 9<\/code><br \/>\nTo say that I&#8217;m impressed is a vast understatement.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I knew that LINQPad was good, but hadn&#8217;t realised that in addition to LINQ proper, one can write whole programs, complete with generics: Function Rank(Of T As {IComparable(Of T)})(items As IEnumerable(Of T), item As T) As Integer Dim ranked = <a href='https:\/\/www.calvert.ch\/maurice\/2014\/01\/31\/linqpad-is-even-better-than-i-thought\/' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[61],"class_list":["post-717","post","type-post","status-publish","format-standard","hentry","category-programming","tag-linq","category-47-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/www.calvert.ch\/maurice\/wp-json\/wp\/v2\/posts\/717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.calvert.ch\/maurice\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.calvert.ch\/maurice\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.calvert.ch\/maurice\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.calvert.ch\/maurice\/wp-json\/wp\/v2\/comments?post=717"}],"version-history":[{"count":7,"href":"https:\/\/www.calvert.ch\/maurice\/wp-json\/wp\/v2\/posts\/717\/revisions"}],"predecessor-version":[{"id":810,"href":"https:\/\/www.calvert.ch\/maurice\/wp-json\/wp\/v2\/posts\/717\/revisions\/810"}],"wp:attachment":[{"href":"https:\/\/www.calvert.ch\/maurice\/wp-json\/wp\/v2\/media?parent=717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.calvert.ch\/maurice\/wp-json\/wp\/v2\/categories?post=717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.calvert.ch\/maurice\/wp-json\/wp\/v2\/tags?post=717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}