<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hi David,<br>
<br>
I think it would be easier to offer feedback if you could
elaborate where the point occurs where you feel the need to drop
out of Streams and into imperative code.<br>
<br>
It is also worth noting that sometimes imperative code is the
right choice for maintainability, reviewability, performance
and/or other reasons.</p>
<div class="moz-cite-prefix">On 2025-11-11 04:36, David Alayachew
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAA9v-_OMFfDGHCOgqDe1jA7LgFZ6hT4owtkd5d5+sxhHOQvCQQ@mail.gmail.com">
<div dir="ltr">
<div class="gmail_default" style="font-family:monospace">Hello <a class="gmail_plusreply" id="plusReplyChip-1" href="mailto:core-libs-dev@openjdk.org" tabindex="-1" moz-do-not-send="true">@core-libs-dev</a>,</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">When
working with streams, I often run into situations where I have
to "demote" back to imperative code because I am trying to
solve a problem best solved by recursion.</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">Consider
the common use case of cycling through permutations to find
all permutations that satisfy some condition. With recursion,
the answer is incredibly simple -- just grab an element from
the set, then call the recursive method with a copy of the set
minus the grabbed element. Once you reach the empty set,
you've reached your terminal condition.</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">Use
cases like that are not only incredibly common, but usually,
embarrassingly parallel. The example above of cycling through
permutations is only a few lines of imperative code, but I
struggle to imagine how I would do this with Streams.</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">I guess
let me start by asking -- are there any good ways currently to
accomplish the above permutation example with Streams? And if
not, should there be?</div>
<div class="gmail_default" style="font-family:monospace"><br>
</div>
<div class="gmail_default" style="font-family:monospace">Thank
you for your time and consideration.</div>
<div class="gmail_default" style="font-family:monospace">David
Alayachew</div>
</div>
</blockquote>
<pre class="moz-signature" cols="72">--
Cheers,
√
Viktor Klang
Software Architect, Java Platform Group
Oracle</pre>
</body>
</html>