<?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"
	>
<channel>
	<title>Comments on: Building a Generic Statistics Library, Part 4: Map</title>
	<atom:link href="http://blogs.teamb.com/craigstuntz/2008/09/17/37837/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.teamb.com/craigstuntz/2008/09/17/37837/</link>
	<description>C# • Entity Framework • Functional Programming • MVC • Web</description>
	<pubDate>Sun, 12 Feb 2012 04:44:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Raymond</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/09/17/37837/#comment-3854</link>
		<dc:creator>Raymond</dc:creator>
		<pubDate>Thu, 18 Sep 2008 19:37:02 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/09/17/37837#comment-3854</guid>
		<description>I agree, the caller has no business in dictating the internal Map implementation. I was just trying to get my head around how returning an IEnumerable to the caller helps with resolving the issue with the sample implementation above constructing the result set.

Ultimately the issue is that delegating creation and management of the result set to the Map() function removes some of the type safety inherent in the approach. The caller is required to perform additional type checks on the result set and the result set is no more than a collection of mutated instances of the original type T (which may not be particularly useful to the caller, or appropriate to the operation being performed).

Anyhoo, this is really just nitpicking and not related to your aim of demonstrating generics. Keep up the good work!</description>
		<content:encoded><![CDATA[<p>I agree, the caller has no business in dictating the internal Map implementation. I was just trying to get my head around how returning an IEnumerable to the caller helps with resolving the issue with the sample implementation above constructing the result set.</p>
<p>Ultimately the issue is that delegating creation and management of the result set to the Map() function removes some of the type safety inherent in the approach. The caller is required to perform additional type checks on the result set and the result set is no more than a collection of mutated instances of the original type T (which may not be particularly useful to the caller, or appropriate to the operation being performed).</p>
<p>Anyhoo, this is really just nitpicking and not related to your aim of demonstrating generics. Keep up the good work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Stuntz</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/09/17/37837/#comment-3852</link>
		<dc:creator>Craig Stuntz</dc:creator>
		<pubDate>Thu, 18 Sep 2008 16:48:59 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/09/17/37837#comment-3852</guid>
		<description>I'm not implying anything about implementation; to the contrary, I'm saying that it is none of the caller's business with the implementation is. However, the caller would see the same result in either case, unless you mutate the list.  But if you mutate the list, there is little need for a function like Map.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not implying anything about implementation; to the contrary, I&#8217;m saying that it is none of the caller&#8217;s business with the implementation is. However, the caller would see the same result in either case, unless you mutate the list.  But if you mutate the list, there is little need for a function like Map.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raymond</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/09/17/37837/#comment-3851</link>
		<dc:creator>Raymond</dc:creator>
		<pubDate>Thu, 18 Sep 2008 16:41:59 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/09/17/37837#comment-3851</guid>
		<description>By 'Ideally I'd like to return an IEnumerable ... rather than constructing an actual list', are you suggesting that the Map() implementation actually be nothing more than an enumerator that calculates individual results from the given list when the caller sucks on it? This would have the, IMO, undesirable effect of synchronising the processing with the act of retrieving the result (something like a Quantum Mechanics approach ;-) ).

Otherwise, I'm not sure how returning an IEnumerable helps as this otherwise needs to be an interface on a concrete container of results which must be constructed somewhere...</description>
		<content:encoded><![CDATA[<p>By &#8216;Ideally I&#8217;d like to return an IEnumerable &#8230; rather than constructing an actual list&#8217;, are you suggesting that the Map() implementation actually be nothing more than an enumerator that calculates individual results from the given list when the caller sucks on it? This would have the, IMO, undesirable effect of synchronising the processing with the act of retrieving the result (something like a Quantum Mechanics approach <img src='http://blogs.teamb.com/craigstuntz/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ).</p>
<p>Otherwise, I&#8217;m not sure how returning an IEnumerable helps as this otherwise needs to be an interface on a concrete container of results which must be constructed somewhere&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Stuntz</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/09/17/37837/#comment-3850</link>
		<dc:creator>Craig Stuntz</dc:creator>
		<pubDate>Thu, 18 Sep 2008 12:50:45 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/09/17/37837#comment-3850</guid>
		<description>Ideally I'd like to return an IEnumerable. This could return the list elements directly rather than constructing an actual list. But D2009's IEnumerable isn't quite fully supported in the RTL, yet.</description>
		<content:encoded><![CDATA[<p>Ideally I&#8217;d like to return an IEnumerable. This could return the list elements directly rather than constructing an actual list. But D2009&#8217;s IEnumerable isn&#8217;t quite fully supported in the RTL, yet.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raymond</title>
		<link>http://blogs.teamb.com/craigstuntz/2008/09/17/37837/#comment-3847</link>
		<dc:creator>Raymond</dc:creator>
		<pubDate>Thu, 18 Sep 2008 03:33:14 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.teamb.com/craigstuntz/2008/09/17/37837#comment-3847</guid>
		<description>Hi Craig,

You know, it's going to take a while to get used to code that looks like this:

 SquaredDeviations := Map(function(AValue: T): T
    begin
      Result := ASquare(ADeviation(AValue, Avg));
    end,
    AData);

Regards the map() function itself, it's not so much returning a new instance, but it is returning a new TList instance, rather than an intance of the TEnumerable derived type. To be truly generic (sic) the map function either needs to be given the list (as yuou suggest), or the type of the required resultant list. The former is parhaps better for lifetime management smoothness (again, as you suggest) and also allows more complex construction semantics for the result list prior to passing to Map().

One minor performance pick ;-) Given this code I would add a line:

NewList.Capacity := AData.Count;

after the construction of newlist to remove the potentially many resizes of the list.

On reflection, I remember you saying that TEnumerable does not support Count (and suggested using a Fold() variant to implement a count). This is possibly another reason to provide Map with the result set.</description>
		<content:encoded><![CDATA[<p>Hi Craig,</p>
<p>You know, it&#8217;s going to take a while to get used to code that looks like this:</p>
<p> SquaredDeviations := Map(function(AValue: T): T<br />
    begin<br />
      Result := ASquare(ADeviation(AValue, Avg));<br />
    end,<br />
    AData);</p>
<p>Regards the map() function itself, it&#8217;s not so much returning a new instance, but it is returning a new TList instance, rather than an intance of the TEnumerable derived type. To be truly generic (sic) the map function either needs to be given the list (as yuou suggest), or the type of the required resultant list. The former is parhaps better for lifetime management smoothness (again, as you suggest) and also allows more complex construction semantics for the result list prior to passing to Map().</p>
<p>One minor performance pick <img src='http://blogs.teamb.com/craigstuntz/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> Given this code I would add a line:</p>
<p>NewList.Capacity := AData.Count;</p>
<p>after the construction of newlist to remove the potentially many resizes of the list.</p>
<p>On reflection, I remember you saying that TEnumerable does not support Count (and suggested using a Fold() variant to implement a count). This is possibly another reason to provide Map with the result set.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

