<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Maurice Naftalin&#039;s Lambda FAQ &#187; Idioms and Techniques</title>
	<atom:link href="https://www.lambdafaq.org/category/idioms-techniques/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lambdafaq.org</link>
	<description>Your questions answered: all about Lambdas and friends</description>
	<lastBuildDate>Tue, 04 May 2021 15:50:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Are there other &#8220;constant&#8221; lambdas like Function.identity()?</title>
		<link>https://www.lambdafaq.org/are-there-other-constant-lambdas-like-function-identity/</link>
		<comments>https://www.lambdafaq.org/are-there-other-constant-lambdas-like-function-identity/#comments</comments>
		<pubDate>Wed, 18 Feb 2015 00:56:57 +0000</pubDate>
		<dc:creator><![CDATA[smarks]]></dc:creator>
				<category><![CDATA[Idioms and Techniques]]></category>

		<guid isPermaLink="false">http://www.lambdafaq.org/?p=1306</guid>
		<description><![CDATA[<p>No, but for many such &#8220;constant&#8221; functions it&#8217;s easy to write your own lambda expression. In fact, one can write x -&#62; x instead of Function.identity() and in some cases it&#8217;s clearer. Here is a list of common constant functions and how they can be written using lambda.</p> <p>Predicate that always returns true or false:</p> [...]]]></description>
				<content:encoded><![CDATA[<p>No, but for many such &#8220;constant&#8221; functions it&#8217;s easy to write your own lambda expression. In fact, one can write <code>x -&gt; x</code> instead of <code>Function.identity()</code> and in some cases it&#8217;s clearer. Here is a list of common constant functions and how they can be written using lambda.</p>
<p>Predicate that always returns true or false:</p>
<p style="padding-left: 30px;"><code>x -&gt; true</code><br />
<code>x -&gt; false</code></p>
<p>Runnable that does nothing:</p>
<p style="padding-left: 30px;"><code>() -&gt; { }</code></p>
<p>Consumer that does nothing:</p>
<p style="padding-left: 30px;"><code>x -&gt; { }</code></p>
<p>Supplier that returns a constant <em>k.</em> This could be a value that&#8217;s captured from the lexical environment, or it could be a literal:</p>
<p style="padding-left: 30px;"><code>() -&gt; k</code></p>
<p>Function that returns a constant <em>k</em>:</p>
<p style="padding-left: 30px;"><code>x -&gt; k</code></p>
<p>Identity function, the same as Function.identity():</p>
<p style="padding-left: 30px;"><code>x -&gt; x</code></p>
<p>Function taking two arguments that returns the first or second:</p>
<p style="padding-left: 30px;"><code>(a, b) -&gt; a</code><br />
<code>(a, b) -&gt; b</code></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.lambdafaq.org/are-there-other-constant-lambdas-like-function-identity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
