<?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: &#8220;For&#8221; hack with Option monad in Java</title>
	<atom:link href="http://codemonkeyism.com/for-hack-with-option-monad-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/</link>
	<description></description>
	<lastBuildDate>Thu, 11 Mar 2010 23:38:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Recent Links Tagged With "monads" - JabberTags</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-177214</link>
		<dc:creator>Recent Links Tagged With "monads" - JabberTags</dc:creator>
		<pubDate>Thu, 09 Oct 2008 14:55:06 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-177214</guid>
		<description>[...] links &gt;&gt; monads   functional programming and monads Saved by SailorStarDust on Wed 08-10-2008   “For” hack with Option monad in Java Saved by zonble on Wed 08-10-2008   Arrows generalize monads and idioms Saved by rmventure on Mon [...]</description>
		<content:encoded><![CDATA[<p>[...] links &gt;&gt; monads   functional programming and monads Saved by SailorStarDust on Wed 08-10-2008   “For” hack with Option monad in Java Saved by zonble on Wed 08-10-2008   Arrows generalize monads and idioms Saved by rmventure on Mon [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-154837</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Mon, 25 Aug 2008 10:54:13 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-154837</guid>
		<description>@3bit: You&#039;re right. But lots of people use [] in blogs and wikis because they are easier to use with most blogging software than pointy braces.</description>
		<content:encoded><![CDATA[<p>@3bit: You&#8217;re right. But lots of people use [] in blogs and wikis because they are easier to use with most blogging software than pointy braces.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 3bit</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-154402</link>
		<dc:creator>3bit</dc:creator>
		<pubDate>Sat, 23 Aug 2008 11:22:51 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-154402</guid>
		<description>Am i completely crazy or is the Type Parameter in Java not usually enclosed in &#039;&#039;?  Or is there a deeper meaning behind this? Since I didn&#039;t trust myself I tried this code in Java but it would give me errors because of the misplaced array &#039;[&#039; &#039;]&#039; qualifiers...</description>
		<content:encoded><![CDATA[<p>Am i completely crazy or is the Type Parameter in Java not usually enclosed in &#8221;?  Or is there a deeper meaning behind this? Since I didn&#8217;t trust myself I tried this code in Java but it would give me errors because of the misplaced array &#8216;[' ']&#8216; qualifiers&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-147232</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Mon, 11 Aug 2008 08:38:56 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-147232</guid>
		<description>Nice!</description>
		<content:encoded><![CDATA[<p>Nice!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lqd</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-147201</link>
		<dc:creator>lqd</dc:creator>
		<pubDate>Mon, 11 Aug 2008 07:25:47 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-147201</guid>
		<description>Where i find this could also work is in adapter patterns (see Tim Boudreau&#039;s last blog about API and &#039;Capability pattern&#039; or Eclipse getAdapter/IAdaptable API)

for (CapabilityClass17 cap : getAdapter (CapabilityClass17.class)) {  
    // do something with the extended API  
}

Ironically, if you think your class had to behave like a list, and you add that adapter later, you could actually get some kind of real looking for loop :)

for (Object s : getAdapter (List.class)) {
    // Booya :)
}

As for the type of the iterator, maybe super type tokens can help.</description>
		<content:encoded><![CDATA[<p>Where i find this could also work is in adapter patterns (see Tim Boudreau&#8217;s last blog about API and &#8216;Capability pattern&#8217; or Eclipse getAdapter/IAdaptable API)</p>
<p>for (CapabilityClass17 cap : getAdapter (CapabilityClass17.class)) {<br />
    // do something with the extended API<br />
}</p>
<p>Ironically, if you think your class had to behave like a list, and you add that adapter later, you could actually get some kind of real looking for loop :)</p>
<p>for (Object s : getAdapter (List.class)) {<br />
    // Booya :)<br />
}</p>
<p>As for the type of the iterator, maybe super type tokens can help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-146482</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Sat, 09 Aug 2008 16:08:29 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-146482</guid>
		<description>&quot;Perhaps you should use try to some patterns that are better fit
for Java like Visitor mentioned by James or Null object.&quot;

I&#039;ve read the GoF Book 15 years ago, taught them to lots of students and used them in lots of projects. I think the Null object (though not from the GoF book but from Fowler several years later) is used not often enough. Recently I introduced NullId to a project (with a nice isValid() method) with very good results. More people should do that.

&quot;Search for design partners or GoF.&quot;

Search for Refactoring and Fowler for the Null object pattern.

Nonetheless Option/Maybe is something different.</description>
		<content:encoded><![CDATA[<p>&#8220;Perhaps you should use try to some patterns that are better fit<br />
for Java like Visitor mentioned by James or Null object.&#8221;</p>
<p>I&#8217;ve read the GoF Book 15 years ago, taught them to lots of students and used them in lots of projects. I think the Null object (though not from the GoF book but from Fowler several years later) is used not often enough. Recently I introduced NullId to a project (with a nice isValid() method) with very good results. More people should do that.</p>
<p>&#8220;Search for design partners or GoF.&#8221;</p>
<p>Search for Refactoring and Fowler for the Null object pattern.</p>
<p>Nonetheless Option/Maybe is something different.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vjekoslav Nesek</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-146292</link>
		<dc:creator>Vjekoslav Nesek</dc:creator>
		<pubDate>Sat, 09 Aug 2008 07:50:13 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-146292</guid>
		<description>Jeez, this double loop construct is so much better than

if (x != null &amp;&amp; y != null) {
  return x   y;
}

...and much more readable.

Perhaps you should use try to some patterns that are better fit
for Java like Visitor mentioned by James or Null object. Search
for design partners or GoF.

Don&#039;t get me wrong, monads are cool but can&#039;t be expressed
in Java at this time. Perhaps if Java7 incorporates closure
proposal, we&#039;ll be able to express something like:

withObjectsThatArentNull(x, y) {
  return x   y;
}</description>
		<content:encoded><![CDATA[<p>Jeez, this double loop construct is so much better than</p>
<p>if (x != null &amp;&amp; y != null) {<br />
  return x   y;<br />
}</p>
<p>&#8230;and much more readable.</p>
<p>Perhaps you should use try to some patterns that are better fit<br />
for Java like Visitor mentioned by James or Null object. Search<br />
for design partners or GoF.</p>
<p>Don&#8217;t get me wrong, monads are cool but can&#8217;t be expressed<br />
in Java at this time. Perhaps if Java7 incorporates closure<br />
proposal, we&#8217;ll be able to express something like:</p>
<p>withObjectsThatArentNull(x, y) {<br />
  return x   y;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Response to the critique for my last post and OneElementIterator at Stephans Blog</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-145948</link>
		<dc:creator>Response to the critique for my last post and OneElementIterator at Stephans Blog</dc:creator>
		<pubDate>Fri, 08 Aug 2008 07:33:17 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-145948</guid>
		<description>[...] Productivity in software development           &#171; &#8220;For&#8221; hack with Option monad in Java [...]</description>
		<content:encoded><![CDATA[<p>[...] Productivity in software development           &laquo; &#8220;For&#8221; hack with Option monad in Java [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-145937</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Fri, 08 Aug 2008 06:52:54 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-145937</guid>
		<description>@James: Thanks a lot.

The double loop is a nice construct. Hats off for thinking of that and the anology to Scala and Haskell with for and do. Especially &quot;for&quot; :-)</description>
		<content:encoded><![CDATA[<p>@James: Thanks a lot.</p>
<p>The double loop is a nice construct. Hats off for thinking of that and the anology to Scala and Haskell with for and do. Especially &#8220;for&#8221; :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Iry</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-145575</link>
		<dc:creator>James Iry</dc:creator>
		<pubDate>Thu, 07 Aug 2008 16:30:47 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-145575</guid>
		<description>My pluses got eaten in the previous comment. Everywhere you see &quot;x y&quot; read &quot;x plus y&quot;.</description>
		<content:encoded><![CDATA[<p>My pluses got eaten in the previous comment. Everywhere you see &#8220;x y&#8221; read &#8220;x plus y&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Iry</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-145562</link>
		<dc:creator>James Iry</dc:creator>
		<pubDate>Thu, 07 Aug 2008 15:17:14 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-145562</guid>
		<description>For the record, the James mentioned in the article is me but the James who was &quot;buggered&quot; up there is not :-)

I have to say, it&#039;s a nice hack.

Another way to deal with Option/Maybe in Java is to use the visitor pattern.  I wrote a quick one for Tony Morris and he used it in a presentation on Scala (where he called it OneOrNone).  The relevant slides are at

http://projects.workingmouse.com/public/intro-to-highlevel-programming-with-scala/artifacts/latest/chunk-html/ar01s08s02.html

and

http://projects.workingmouse.com/public/intro-to-highlevel-programming-with-scala/artifacts/latest/chunk-html/ar01s08s03.html

However, as Jevgeni points out, the real nifty bit about Option/Maybe as a monad is composibility.  E.g. in Scala

val maybeSum = for {
  x &lt;- someMaybe
  y &lt;- someOtherMaybe
} yield x + y

or Haskell

let maybeSum = do 
                   x &lt;- someMaybe
                   y &lt;- someOtherMaybe
                   return x + y

The iterator trick in Java, by contrast, yields the following 

Option[Integer] maybeSum = new None[Integer]();
for (x:someMaybe) {
       for(y:someOtherMaybe) {
           maybeSum = new Some(x + y);
       }
}

Still, that&#039;s much nicer than the manual instanceof/extraction I had and a bit nicer than using a bunch of nested visitors.  Hats off!

[Ed: Added + see next comment]</description>
		<content:encoded><![CDATA[<p>For the record, the James mentioned in the article is me but the James who was &#8220;buggered&#8221; up there is not :-)</p>
<p>I have to say, it&#8217;s a nice hack.</p>
<p>Another way to deal with Option/Maybe in Java is to use the visitor pattern.  I wrote a quick one for Tony Morris and he used it in a presentation on Scala (where he called it OneOrNone).  The relevant slides are at</p>
<p><a href="http://projects.workingmouse.com/public/intro-to-highlevel-programming-with-scala/artifacts/latest/chunk-html/ar01s08s02.html" rel="nofollow">http://projects.workingmouse.com/public/intro-to-highlevel-programming-with-scala/artifacts/latest/chunk-html/ar01s08s02.html</a></p>
<p>and</p>
<p><a href="http://projects.workingmouse.com/public/intro-to-highlevel-programming-with-scala/artifacts/latest/chunk-html/ar01s08s03.html" rel="nofollow">http://projects.workingmouse.com/public/intro-to-highlevel-programming-with-scala/artifacts/latest/chunk-html/ar01s08s03.html</a></p>
<p>However, as Jevgeni points out, the real nifty bit about Option/Maybe as a monad is composibility.  E.g. in Scala</p>
<p>val maybeSum = for {<br />
  x &lt;- someMaybe<br />
  y &lt;- someOtherMaybe<br />
} yield x + y</p>
<p>or Haskell</p>
<p>let maybeSum = do<br />
                   x &lt;- someMaybe<br />
                   y &lt;- someOtherMaybe<br />
                   return x + y</p>
<p>The iterator trick in Java, by contrast, yields the following </p>
<p>Option[Integer] maybeSum = new None[Integer]();<br />
for (x:someMaybe) {<br />
       for(y:someOtherMaybe) {<br />
           maybeSum = new Some(x + y);<br />
       }<br />
}</p>
<p>Still, that&#8217;s much nicer than the manual instanceof/extraction I had and a bit nicer than using a bunch of nested visitors.  Hats off!</p>
<p>[Ed: Added + see next comment]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-145416</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 07 Aug 2008 08:11:25 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-145416</guid>
		<description>@Kieron: Thanks. And I&#039;m scared too :-) At least it shows that I&#039;m not crazy ... or the only one.

@BoD: a.) The developer has to deal with the None case, with NULL he can just ignore it b.) The developer knows there is a None case, with NULL he can&#039;t see it in the method signature. And see the linked posts: NULL can mean lots of things (error, no result, etc.), None is much better.</description>
		<content:encoded><![CDATA[<p>@Kieron: Thanks. And I&#8217;m scared too :-) At least it shows that I&#8217;m not crazy &#8230; or the only one.</p>
<p>@BoD: a.) The developer has to deal with the None case, with NULL he can just ignore it b.) The developer knows there is a None case, with NULL he can&#8217;t see it in the method signature. And see the linked posts: NULL can mean lots of things (error, no result, etc.), None is much better.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kieron Wilkinson</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-145409</link>
		<dc:creator>Kieron Wilkinson</dc:creator>
		<pubDate>Thu, 07 Aug 2008 07:43:02 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-145409</guid>
		<description>Excellent post. And scary, I did exactly the same in my &quot;Optional&quot; class yesterday...</description>
		<content:encoded><![CDATA[<p>Excellent post. And scary, I did exactly the same in my &#8220;Optional&#8221; class yesterday&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BoD</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-145001</link>
		<dc:creator>BoD</dc:creator>
		<pubDate>Wed, 06 Aug 2008 17:09:01 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-145001</guid>
		<description>Why is 

for (String name: option) {  
    // do something with name  
}  

better than

if (name != null) {
    // do something with name  
}</description>
		<content:encoded><![CDATA[<p>Why is </p>
<p>for (String name: option) {<br />
    // do something with name<br />
}  </p>
<p>better than</p>
<p>if (name != null) {<br />
    // do something with name<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-144987</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 06 Aug 2008 15:27:53 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-144987</guid>
		<description>@Vjekoslav: While Option can be seen as a 0..1 container, the reverse isn&#039;t true. A Collection is not a Maybe/option.

@Cedric: Thanks. From an unrelated post &quot;Others I’d like to meet are above all Crazy Bob for Dynaop (and Guice), Cedric for his stand on dynamic languages and Rickard of course.&quot; ;-)

@Jevgeni: Yes, of course your&#039;re right. That wasn&#039;t the focus of this point. While this isn&#039;t that powerful for Option, combination and mapping is very powerful for Either.</description>
		<content:encoded><![CDATA[<p>@Vjekoslav: While Option can be seen as a 0..1 container, the reverse isn&#8217;t true. A Collection is not a Maybe/option.</p>
<p>@Cedric: Thanks. From an unrelated post &#8220;Others I’d like to meet are above all Crazy Bob for Dynaop (and Guice), Cedric for his stand on dynamic languages and Rickard of course.&#8221; ;-)</p>
<p>@Jevgeni: Yes, of course your&#8217;re right. That wasn&#8217;t the focus of this point. While this isn&#8217;t that powerful for Option, combination and mapping is very powerful for Either.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jevgeni Kabanov</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-144975</link>
		<dc:creator>Jevgeni Kabanov</dc:creator>
		<pubDate>Wed, 06 Aug 2008 15:13:36 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-144975</guid>
		<description>The main point of Monads is the way you can combine them. E.g. in Haskell the point of &quot;do&quot; is not just that you don&#039;t have to handle empty cases, but that you can have a succession of operations returning empty that you can handle seamlessly. I do like where you&#039;re going, though :)</description>
		<content:encoded><![CDATA[<p>The main point of Monads is the way you can combine them. E.g. in Haskell the point of &#8220;do&#8221; is not just that you don&#8217;t have to handle empty cases, but that you can have a succession of operations returning empty that you can handle seamlessly. I do like where you&#8217;re going, though :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cedric</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-144968</link>
		<dc:creator>Cedric</dc:creator>
		<pubDate>Wed, 06 Aug 2008 15:01:49 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-144968</guid>
		<description>Cute hack, Stephan :-)</description>
		<content:encoded><![CDATA[<p>Cute hack, Stephan :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vjekoslav Nesek</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-144957</link>
		<dc:creator>Vjekoslav Nesek</dc:creator>
		<pubDate>Wed, 06 Aug 2008 14:13:58 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-144957</guid>
		<description>You already have that class in Java libs, it&#039;s called Collection. Just use a Collection[String] instead of Option[String] and not have to code two additional classes.

// NULL name
Collection name = Collections.emptySet();

// Value
Collection name = Collections.singletonSet(&quot;Joe&quot;);

for (String n : name) {
  // Do something
}

IMHO... Not a good idiom. It&#039;s to much work to prevent NPE and would confuse whoever needs to maintain code.</description>
		<content:encoded><![CDATA[<p>You already have that class in Java libs, it&#8217;s called Collection. Just use a Collection[String] instead of Option[String] and not have to code two additional classes.</p>
<p>// NULL name<br />
Collection name = Collections.emptySet();</p>
<p>// Value<br />
Collection name = Collections.singletonSet(&#8220;Joe&#8221;);</p>
<p>for (String n : name) {<br />
  // Do something<br />
}</p>
<p>IMHO&#8230; Not a good idiom. It&#8217;s to much work to prevent NPE and would confuse whoever needs to maintain code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-144898</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Wed, 06 Aug 2008 12:37:49 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-144898</guid>
		<description>No, on the contrary:

&lt;i&gt;&quot;And then you return 2 names from the getName method and you a buggered…&quot;&lt;/i&gt;

The return type of the getName() is Option[T],  so you can&#039;t return more than one without changing the signature.

In the case that you don&#039;t declare the return type in your client code:

a.) If your code handles 0 or 1 return values (None/Some) with a &lt;code&gt;for&lt;/code&gt; and does something, like add the name to an index, or add the name to a cache, or validate the name, then your logic also works for more than one name. And you don&#039;t need to change the client &lt;code&gt;for&lt;/code&gt; loop of your code. 

b.) If you need to handle 0 and 1 and n in different ways (what most often you don&#039;t), then the &lt;code&gt;for&lt;/code&gt; hack isn&#039;t suitable of course.

&lt;i&gt;&quot;I think this for loop would just confuse me in a months time,  [...]&quot;&lt;/i&gt;

Not if you think of an Option as a 0..1 element container.</description>
		<content:encoded><![CDATA[<p>No, on the contrary:</p>
<p><i>&#8220;And then you return 2 names from the getName method and you a buggered…&#8221;</i></p>
<p>The return type of the getName() is Option[T],  so you can&#8217;t return more than one without changing the signature.</p>
<p>In the case that you don&#8217;t declare the return type in your client code:</p>
<p>a.) If your code handles 0 or 1 return values (None/Some) with a <code>for</code> and does something, like add the name to an index, or add the name to a cache, or validate the name, then your logic also works for more than one name. And you don&#8217;t need to change the client <code>for</code> loop of your code. </p>
<p>b.) If you need to handle 0 and 1 and n in different ways (what most often you don&#8217;t), then the <code>for</code> hack isn&#8217;t suitable of course.</p>
<p><i>&#8220;I think this for loop would just confuse me in a months time,  [...]&#8220;</i></p>
<p>Not if you think of an Option as a 0..1 element container.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://codemonkeyism.com/for-hack-with-option-monad-in-java/comment-page-1/#comment-144862</link>
		<dc:creator>James</dc:creator>
		<pubDate>Wed, 06 Aug 2008 11:14:53 +0000</pubDate>
		<guid isPermaLink="false">http://stephan.reposita.org/archives/2008/08/06/for-hack-with-option-monad-in-java/#comment-144862</guid>
		<description>And then you return 2 names from the getName method and you a buggered...

I think this for loop would just confuse me in a months time, not to mention my collegues.</description>
		<content:encoded><![CDATA[<p>And then you return 2 names from the getName method and you a buggered&#8230;</p>
<p>I think this for loop would just confuse me in a months time, not to mention my collegues.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
