<?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: Erlang Programming Exercise: 3-7</title>
	<atom:link href="http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-7/feed/" rel="self" type="application/rss+xml" />
	<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-7/</link>
	<description>// [bgh] todo, add something clever here.</description>
	<lastBuildDate>Wed, 09 Mar 2011 02:11:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: halzy</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-7/comment-page-1/#comment-601</link>
		<dc:creator>halzy</dc:creator>
		<pubDate>Wed, 09 Mar 2011 02:11:50 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=142#comment-601</guid>
		<description>I haven&#039;t made it far enough in the book to use the list comprehension. I saw it when reading through the other book, but wanted to keep with what had been taught so far in this book.</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t made it far enough in the book to use the list comprehension. I saw it when reading through the other book, but wanted to keep with what had been taught so far in this book.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://benjaminhalsted.com/2010/03/erlang-programming-exercise-3-7/comment-page-1/#comment-531</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Tue, 14 Sep 2010 21:02:24 +0000</pubDate>
		<guid isPermaLink="false">http://benjaminhalsted.com/?p=142#comment-531</guid>
		<description>&quot;case&quot; in match/2 can be omitted:

match(Element, Db) -&gt;
	lists:filter(fun({_, E}) -&gt; E =:= Element end, Db).

but original exercise required that match/2 returns list of keys, not list of tuples, so it could look like:

match(Element, Db) -&gt;
	MatchedTuples = lists:filter(fun({_, E}) -&gt; E =:= Element end, Db),
	element(1, lists:unzip(MatchedTuples)).

But this is rather too complicated. Using list comprehension gives us a simpler version:

match(Element, Db) -&gt;
	[Key &#124;&#124; {Key, E} &lt;- Db, E =:= Element].</description>
		<content:encoded><![CDATA[<p>&#8220;case&#8221; in match/2 can be omitted:</p>
<p>match(Element, Db) -&gt;<br />
	lists:filter(fun({_, E}) -&gt; E =:= Element end, Db).</p>
<p>but original exercise required that match/2 returns list of keys, not list of tuples, so it could look like:</p>
<p>match(Element, Db) -&gt;<br />
	MatchedTuples = lists:filter(fun({_, E}) -&gt; E =:= Element end, Db),<br />
	element(1, lists:unzip(MatchedTuples)).</p>
<p>But this is rather too complicated. Using list comprehension gives us a simpler version:</p>
<p>match(Element, Db) -&gt;<br />
	[Key || {Key, E} &lt;- Db, E =:= Element].</p>
]]></content:encoded>
	</item>
</channel>
</rss>

