<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Functional C#: Extracting a higher order function with generics</title>
	<atom:link href="http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Sat, 11 Feb 2012 23:17:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Mark Needham</title>
		<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/comment-page-1/#comment-31721</link>
		<dc:creator>Mark Needham</dc:creator>
		<pubDate>Tue, 09 Feb 2010 22:36:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2129#comment-31721</guid>
		<description>@David - yeah good point your solution would work better, didn&#039;t think of that.

@Matt - haven&#039;t done anything with constraints as yet because it didn&#039;t seem necessary for what we were doing so far. I guess if it was a completely generic function that was used all over the code then constraints would make sense. 

@Michael - in fact in this case the two services don&#039;t implement the same interface otherwise your suggestion would certainly be the way to go.</description>
		<content:encoded><![CDATA[<p>@David &#8211; yeah good point your solution would work better, didn&#8217;t think of that.</p>
<p>@Matt &#8211; haven&#8217;t done anything with constraints as yet because it didn&#8217;t seem necessary for what we were doing so far. I guess if it was a completely generic function that was used all over the code then constraints would make sense. </p>
<p>@Michael &#8211; in fact in this case the two services don&#8217;t implement the same interface otherwise your suggestion would certainly be the way to go.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ollie Riches</title>
		<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/comment-page-1/#comment-31707</link>
		<dc:creator>Ollie Riches</dc:creator>
		<pubDate>Tue, 09 Feb 2010 17:48:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2129#comment-31707</guid>
		<description>I&#039;ve started doing this all thetime when I have functionality that uses the same exception handling.

nice to see other poeple doing this as well.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve started doing this all thetime when I have functionality that uses the same exception handling.</p>
<p>nice to see other poeple doing this as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carsten</title>
		<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/comment-page-1/#comment-31697</link>
		<dc:creator>Carsten</dc:creator>
		<pubDate>Tue, 09 Feb 2010 12:26:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2129#comment-31697</guid>
		<description>Hi Matt,
just add constraints if you need them.</description>
		<content:encoded><![CDATA[<p>Hi Matt,<br />
just add constraints if you need them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Chandler</title>
		<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/comment-page-1/#comment-31692</link>
		<dc:creator>Michael Chandler</dc:creator>
		<pubDate>Tue, 09 Feb 2010 10:42:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2129#comment-31692</guid>
		<description>Gah... they were IService(Of T) and IEnumerable(Of T) but you blog stripped them out.</description>
		<content:encoded><![CDATA[<p>Gah&#8230; they were IService(Of T) and IEnumerable(Of T) but you blog stripped them out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Chandler</title>
		<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/comment-page-1/#comment-31691</link>
		<dc:creator>Michael Chandler</dc:creator>
		<pubDate>Tue, 09 Feb 2010 10:41:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2129#comment-31691</guid>
		<description>If barService and fooService both implement IService which contains an IEnumerable GetFor(Guid id) then I think it&#039;d be clearer to pass in an IService into GetValues rather than the Func&lt;IEnumerable&gt;.

I find myself doing this stuff all the time now though. It&#039;s nice.</description>
		<content:encoded><![CDATA[<p>If barService and fooService both implement IService which contains an IEnumerable GetFor(Guid id) then I think it&#8217;d be clearer to pass in an IService into GetValues rather than the Func&lt;IEnumerable&gt;.</p>
<p>I find myself doing this stuff all the time now though. It&#8217;s nice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Warren</title>
		<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/comment-page-1/#comment-31687</link>
		<dc:creator>Matt Warren</dc:creator>
		<pubDate>Tue, 09 Feb 2010 09:35:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2129#comment-31687</guid>
		<description>Mark,

Would you ever add any type constraints to the generic function, i.e. &quot;where T : ISomeInterface&quot; or where T : class, new()&quot; or do you not go that far because you&#039;re passing in the Func(..) that gets the values, so it can handle that?</description>
		<content:encoded><![CDATA[<p>Mark,</p>
<p>Would you ever add any type constraints to the generic function, i.e. &#8220;where T : ISomeInterface&#8221; or where T : class, new()&#8221; or do you not go that far because you&#8217;re passing in the Func(..) that gets the values, so it can handle that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Kemp</title>
		<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/comment-page-1/#comment-31686</link>
		<dc:creator>David Kemp</dc:creator>
		<pubDate>Tue, 09 Feb 2010 09:34:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2129#comment-31686</guid>
		<description>and you comments strips the &lt;T&gt;, damn!</description>
		<content:encoded><![CDATA[<p>and you comments strips the &lt;T&gt;, damn!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Kemp</title>
		<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/comment-page-1/#comment-31685</link>
		<dc:creator>David Kemp</dc:creator>
		<pubDate>Tue, 09 Feb 2010 09:32:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2129#comment-31685</guid>
		<description>Why do you always create a new list?

IEnumerable values = new List();
   
C# has a perfectly good coalescing operator (??) that you can use:

return values ?? new List();

This way the allocation only happens when you haven&#039;t been able to get the list (or if your getValues() function returns null)</description>
		<content:encoded><![CDATA[<p>Why do you always create a new list?</p>
<p>IEnumerable values = new List();</p>
<p>C# has a perfectly good coalescing operator (??) that you can use:</p>
<p>return values ?? new List();</p>
<p>This way the allocation only happens when you haven&#8217;t been able to get the list (or if your getValues() function returns null)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Morning Brew - Chris Alcock &#187; The Morning Brew #535</title>
		<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/comment-page-1/#comment-31684</link>
		<dc:creator>The Morning Brew - Chris Alcock &#187; The Morning Brew #535</dc:creator>
		<pubDate>Tue, 09 Feb 2010 08:38:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2129#comment-31684</guid>
		<description>[...] Functional C#: Extracting a higher order function with generics - Mark Needham continues his exploration of being more functional in your C# code illustrating with an example of refactoring a set of similar looking function calls which differed only by the service the call and the type they return. [...]</description>
		<content:encoded><![CDATA[<p>[...] Functional C#: Extracting a higher order function with generics &#8211; Mark Needham continues his exploration of being more functional in your C# code illustrating with an example of refactoring a set of similar looking function calls which differed only by the service the call and the type they return. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carsten</title>
		<link>http://www.markhneedham.com/blog/2010/02/08/functional-c-extracting-a-higher-order-function-with-generics/comment-page-1/#comment-31678</link>
		<dc:creator>Carsten</dc:creator>
		<pubDate>Tue, 09 Feb 2010 06:25:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2129#comment-31678</guid>
		<description>Hi,

I more and more end up with similiar code.
Some times my code look like

.... =&gt; {
          ....
          ....
          .... =&gt; {
                   etc.
                  }
         }

BTW: why use the IEnumerable instead of plain T?
In some cases the C# intference is not able to get it right but in most cases it works for me just fine.

Heres one of my favs from my common DAL:

public virtual IEnumerable&lt;LazyReadonly&gt; GetAll()
{ return GetEnumerable(
     env =&gt;
         UseDataAdapter(
            env,
            adp =&gt;
                GetAllRows(adp)
                .Select(r =&gt;
                          LazyReadonly.Create(
                             GetKeyFromRow(r),
                             () =&gt; RowToItem(r))
                         )));
        }

;) (ok it messed up the spacing ... thats something I didn&#039;t figure out for my code yet - how to space the lines)</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I more and more end up with similiar code.<br />
Some times my code look like</p>
<p>&#8230;. =&gt; {<br />
          &#8230;.<br />
          &#8230;.<br />
          &#8230;. =&gt; {<br />
                   etc.<br />
                  }<br />
         }</p>
<p>BTW: why use the IEnumerable instead of plain T?<br />
In some cases the C# intference is not able to get it right but in most cases it works for me just fine.</p>
<p>Heres one of my favs from my common DAL:</p>
<p>public virtual IEnumerable&lt;LazyReadonly&gt; GetAll()<br />
{ return GetEnumerable(<br />
     env =&gt;<br />
         UseDataAdapter(<br />
            env,<br />
            adp =&gt;<br />
                GetAllRows(adp)<br />
                .Select(r =&gt;<br />
                          LazyReadonly.Create(<br />
                             GetKeyFromRow(r),<br />
                             () =&gt; RowToItem(r))<br />
                         )));<br />
        }</p>
<p> <img src='http://www.markhneedham.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  (ok it messed up the spacing &#8230; thats something I didn&#8217;t figure out for my code yet &#8211; how to space the lines)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

