<?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; naftalin</title>
	<atom:link href="https://www.lambdafaq.org/author/naftalin/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>In what order do the elements of a stream become available?</title>
		<link>https://www.lambdafaq.org/in-what-order-do-the-elements-of-a-stream-become-available/</link>
		<comments>https://www.lambdafaq.org/in-what-order-do-the-elements-of-a-stream-become-available/#comments</comments>
		<pubDate>Sat, 09 Aug 2014 22:06:02 +0000</pubDate>
		<dc:creator><![CDATA[naftalin]]></dc:creator>
				<category><![CDATA[Advanced Questions]]></category>

		<guid isPermaLink="false">http://www.lambdafaq.org/?p=1077</guid>
		<description><![CDATA[<p>The order in which a stream&#8217;s elements are made available to the &#8220;downstream&#8221; operation (the one that ends it) depends on its source. There are two main possibilities:</p> The source has an encounter order : this is the order in which the source itself makes its elements available. For example, the encounter order for an [...]]]></description>
				<content:encoded><![CDATA[<p>The order in which a stream&#8217;s elements are made available to the &#8220;downstream&#8221; operation (the one that ends it) depends on its source. There are two main possibilities:</p>
<ul>
<li>The source has an <span class="glossary-term" onmouseover="TagToTip('encounterOrder', FOLLOWMOUSE, false, STICKY, true, DURATION, 5000)"><em>encounter order</em></span> : this is the order in which the source itself makes its elements available. For example, the encounter order for an array is defined by the ordering of its elements; for an ordered collection like a <code>List</code> or a <code>NavigableMap</code>, by its iteration order; for a generator function by the function itself, and so on.</li>
<li>The source has no encounter order. For example, a <code>Set</code>, which is inherently unordered, has none.</li>
</ul>
<p>The operation that terminates a stream may be an intermediate operation feeding its results into the next component stream of the pipeline, or a terminal operation ending the pipeline as a whole. Each intermediate or terminal operation acts on the encounter order in one of three ways:
<ul>
<li>An encounter order may be imposed on the output. For example, the output of <code>sorted</code> always has one;</li>
<li>It may preserve an existing encounter order if there is one. For example, <code>filter</code> may drop some elements from the stream, but the order of the surviving elements is unchanged;</li>
<li>It may destroy an existing encounter order. For example, the new encounter order imposed by <code>sorted</code> will replace any existing one. </li>
</ul>
<p>Collectors preserve encounter order if they are accumulating into a container that itself has an encounter order. For example, collection into an array will place the elements into the array in the encounter order of the stream.  This is an example of a terminal operation that <em>requires</em> an ordering on its input. Such operations—non-commutative reductions are another example—will assign an arbitrary order to an unordered stream.</p>
<p>The explanation above applies to <code>forEachOrdered</code>, but not to any other operation that works by side-effect (e.g. <code>forEach</code> and <code>peek</code>). For these operations, no guarantee is made about execution order of side-effects for any stream, whether ordered or unordered.   </p>
<p>Sequential and parallel streams have the same properties with respect to ordering. </p>
<p>The <code>unordered</code> method may be applied to a stream to indicate to the implementation that a stream&#8217;s encounter order can be disregarded. Parallel streams may perform some operations more efficiently when they do not have to respect the ordering of stream elements. </p>
<p><span id="encounterOrder">This name is not very descriptive. Encounter order can best be thought of as the <em>spatial</em> ordering of elements in a collection or other source.</span> </p>
]]></content:encoded>
			<wfw:commentRss>https://www.lambdafaq.org/in-what-order-do-the-elements-of-a-stream-become-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
