<?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 Collection Parameters: Handling the null collection</title>
	<atom:link href="http://www.markhneedham.com/blog/2009/06/16/functional-collection-parameters-handling-the-null-collection/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog/2009/06/16/functional-collection-parameters-handling-the-null-collection/</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: Functional Collection Parameters: A different way of thinking about collections at Mark Needham</title>
		<link>http://www.markhneedham.com/blog/2009/06/16/functional-collection-parameters-handling-the-null-collection/comment-page-1/#comment-18882</link>
		<dc:creator>Functional Collection Parameters: A different way of thinking about collections at Mark Needham</dc:creator>
		<pubDate>Fri, 19 Jun 2009 13:29:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1340#comment-18882</guid>
		<description>[...] written previously about the ways I&#039;ve been making use of functional collection parameters in my code but what I hadn&#039;t really considered was that the way of thinking [...]</description>
		<content:encoded><![CDATA[<p>[...] written previously about the ways I&#8217;ve been making use of functional collection parameters in my code but what I hadn&#8217;t really considered was that the way of thinking [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Iain B</title>
		<link>http://www.markhneedham.com/blog/2009/06/16/functional-collection-parameters-handling-the-null-collection/comment-page-1/#comment-18778</link>
		<dc:creator>Iain B</dc:creator>
		<pubDate>Wed, 17 Jun 2009 10:04:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1340#comment-18778</guid>
		<description>I can&#039;t remember if you&#039;ve written about the null-coalescing operator &#039;??&#039;, but I&#039;ve been using it a lot to remove all those annoying &#039;if (x == null)&#039;s

return (source ?? new List() ).Select(selector) ;</description>
		<content:encoded><![CDATA[<p>I can&#8217;t remember if you&#8217;ve written about the null-coalescing operator &#8216;??&#8217;, but I&#8217;ve been using it a lot to remove all those annoying &#8216;if (x == null)&#8217;s</p>
<p>return (source ?? new List() ).Select(selector) ;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Needham</title>
		<link>http://www.markhneedham.com/blog/2009/06/16/functional-collection-parameters-handling-the-null-collection/comment-page-1/#comment-18753</link>
		<dc:creator>Mark Needham</dc:creator>
		<pubDate>Tue, 16 Jun 2009 21:33:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1340#comment-18753</guid>
		<description>That&#039;s a pretty neat idea, hadn&#039;t thought of that. I guess that also has the benefit of making it more obvious what&#039;s going on</description>
		<content:encoded><![CDATA[<p>That&#8217;s a pretty neat idea, hadn&#8217;t thought of that. I guess that also has the benefit of making it more obvious what&#8217;s going on</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Ammerman</title>
		<link>http://www.markhneedham.com/blog/2009/06/16/functional-collection-parameters-handling-the-null-collection/comment-page-1/#comment-18739</link>
		<dc:creator>Chris Ammerman</dc:creator>
		<pubDate>Tue, 16 Jun 2009 15:48:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1340#comment-18739</guid>
		<description>Arg, all my generics got dropped by the sanitizer....

I also forgot to note that the EmptyIfNull approach is really nice because then all of the non-aggregatory IEnumerable operations will automatically work because they all know how to handle an empty collection!  So, just one function to enable all operations, instead of one for each.</description>
		<content:encoded><![CDATA[<p>Arg, all my generics got dropped by the sanitizer&#8230;.</p>
<p>I also forgot to note that the EmptyIfNull approach is really nice because then all of the non-aggregatory IEnumerable operations will automatically work because they all know how to handle an empty collection!  So, just one function to enable all operations, instead of one for each.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Ammerman</title>
		<link>http://www.markhneedham.com/blog/2009/06/16/functional-collection-parameters-handling-the-null-collection/comment-page-1/#comment-18738</link>
		<dc:creator>Chris Ammerman</dc:creator>
		<pubDate>Tue, 16 Jun 2009 15:45:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1340#comment-18738</guid>
		<description>Another way around this is an extension method to IEnumerable that will pass through non-null source and return Enumerable.Empty() for a null source:

IEnumerable EmptyIfNull(this IEnumerable source)
{
	if (source == null)
		return Enumerable.Empty();

	return source;
}

Then your function can look like this:

private IEnumerable MapFooMessages(IEnumerable fooMessages)
{
	return
		fooMessages
			.EmptyIfNull()
			.Select(eachFooMessage =&gt; new Foo(fooMessage));
}</description>
		<content:encoded><![CDATA[<p>Another way around this is an extension method to IEnumerable that will pass through non-null source and return Enumerable.Empty() for a null source:</p>
<p>IEnumerable EmptyIfNull(this IEnumerable source)<br />
{<br />
	if (source == null)<br />
		return Enumerable.Empty();</p>
<p>	return source;<br />
}</p>
<p>Then your function can look like this:</p>
<p>private IEnumerable MapFooMessages(IEnumerable fooMessages)<br />
{<br />
	return<br />
		fooMessages<br />
			.EmptyIfNull()<br />
			.Select(eachFooMessage =&gt; new Foo(fooMessage));<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

