Iterator for something generated recursively (without pre-generating the results) The Next CEO of Stack OverflowCan every recursion be converted into iteration?How to do a cyclic doubly link list add method in javaWay to go from recursion to iterationFastest way to determine if an integer's square root is an integerEfficiency of Java “Double Brace Initialization”?Difference between Python's Generators and IteratorsDifference between Java SE/EE/ME?Recursive generators in PHPRecursive generator in C++Converting recursive algorithm to IterativeRecursive to iterative when using recursive-result for other calculatonsConvert recursive function to iterative function

The Ultimate Number Sequence Puzzle

Plausibility of squid whales

What happened in Rome, when the western empire "fell"?

Computationally populating tables with probability data

Inductor and Capacitor in Parallel

Audio Conversion With ADS1243

Can I board the first leg of the flight without having final country's visa?

What's the commands of Cisco query bgp neighbor table, bgp table and router table?

Does the Idaho Potato Commission associate potato skins with healthy eating?

What difference does it make using sed with/without whitespaces?

Where do students learn to solve polynomial equations these days?

Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico

In the "Harry Potter and the Order of the Phoenix" video game, what potion is used to sabotage Umbridge's speakers?

What steps are necessary to read a Modern SSD in Medieval Europe?

Is French Guiana a (hard) EU border?

Man transported from Alternate World into ours by a Neutrino Detector

Cannot shrink btrfs filesystem although there is still data and metadata space left : ERROR: unable to resize '/home': No space left on device

TikZ: How to fill area with a special pattern?

Is Nisuin Biblical or Rabbinic?

What would be the main consequences for a country leaving the WTO?

Won the lottery - how do I keep the money?

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Does Germany produce more waste than the US?

Why am I getting "Static method cannot be referenced from a non static context: String String.valueOf(Object)"?



Iterator for something generated recursively (without pre-generating the results)



The Next CEO of Stack OverflowCan every recursion be converted into iteration?How to do a cyclic doubly link list add method in javaWay to go from recursion to iterationFastest way to determine if an integer's square root is an integerEfficiency of Java “Double Brace Initialization”?Difference between Python's Generators and IteratorsDifference between Java SE/EE/ME?Recursive generators in PHPRecursive generator in C++Converting recursive algorithm to IterativeRecursive to iterative when using recursive-result for other calculatonsConvert recursive function to iterative function










1















I want to create an Iterator in Java (i.e. support hasNext() and next() calls). However, the thing I'm iterating is generated recursively. I want to be able to create this Iterator without having to generate the values beforehand and storing them. Instead, the next() call should get the next value that the recursion outputs, and hasNext() should check that the recursion is not yet done.



Is there a standard pattern for doing this?



Edit: I think a Python yield in a recursive function is the functionality I'm looking for. Not sure how to do it in Java though.










share|improve this question
























  • Check out my code here. May be this is what you are looking for, if not then at least could offer some hints.

    – Rahul R.
    Mar 21 at 19:13






  • 1





    Can you show an example of the recursive algorithm? Using iterators it's often possible to convert a recursive algorithm into an iterative one by retaining the state between calls to next().

    – Alnitak
    Mar 21 at 19:59











  • I figured out an iterative solution to my specific problem: I was trying to generate all subsets of a certain size for a given set. I do this iteratively now by incrementing a set of indices on the original set. I'll leave the question open though, since I think there are definitely algorithms where it's difficult to get an iterative solution.

    – rococo
    Mar 21 at 20:31






  • 1





    See e.g.jdoodle.com/a/15tZ, where I've generated an O(1) algorithm using iterators to generate each member of the Fibonacci sequence.

    – Alnitak
    Mar 21 at 20:32







  • 1





    stackoverflow.com/questions/931762/…

    – Alnitak
    Mar 21 at 20:33















1















I want to create an Iterator in Java (i.e. support hasNext() and next() calls). However, the thing I'm iterating is generated recursively. I want to be able to create this Iterator without having to generate the values beforehand and storing them. Instead, the next() call should get the next value that the recursion outputs, and hasNext() should check that the recursion is not yet done.



Is there a standard pattern for doing this?



Edit: I think a Python yield in a recursive function is the functionality I'm looking for. Not sure how to do it in Java though.










share|improve this question
























  • Check out my code here. May be this is what you are looking for, if not then at least could offer some hints.

    – Rahul R.
    Mar 21 at 19:13






  • 1





    Can you show an example of the recursive algorithm? Using iterators it's often possible to convert a recursive algorithm into an iterative one by retaining the state between calls to next().

    – Alnitak
    Mar 21 at 19:59











  • I figured out an iterative solution to my specific problem: I was trying to generate all subsets of a certain size for a given set. I do this iteratively now by incrementing a set of indices on the original set. I'll leave the question open though, since I think there are definitely algorithms where it's difficult to get an iterative solution.

    – rococo
    Mar 21 at 20:31






  • 1





    See e.g.jdoodle.com/a/15tZ, where I've generated an O(1) algorithm using iterators to generate each member of the Fibonacci sequence.

    – Alnitak
    Mar 21 at 20:32







  • 1





    stackoverflow.com/questions/931762/…

    – Alnitak
    Mar 21 at 20:33













1












1








1








I want to create an Iterator in Java (i.e. support hasNext() and next() calls). However, the thing I'm iterating is generated recursively. I want to be able to create this Iterator without having to generate the values beforehand and storing them. Instead, the next() call should get the next value that the recursion outputs, and hasNext() should check that the recursion is not yet done.



Is there a standard pattern for doing this?



Edit: I think a Python yield in a recursive function is the functionality I'm looking for. Not sure how to do it in Java though.










share|improve this question
















I want to create an Iterator in Java (i.e. support hasNext() and next() calls). However, the thing I'm iterating is generated recursively. I want to be able to create this Iterator without having to generate the values beforehand and storing them. Instead, the next() call should get the next value that the recursion outputs, and hasNext() should check that the recursion is not yet done.



Is there a standard pattern for doing this?



Edit: I think a Python yield in a recursive function is the functionality I'm looking for. Not sure how to do it in Java though.







java recursion iterator iteration






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 19:20







rococo

















asked Mar 21 at 19:09









rococorococo

4511517




4511517












  • Check out my code here. May be this is what you are looking for, if not then at least could offer some hints.

    – Rahul R.
    Mar 21 at 19:13






  • 1





    Can you show an example of the recursive algorithm? Using iterators it's often possible to convert a recursive algorithm into an iterative one by retaining the state between calls to next().

    – Alnitak
    Mar 21 at 19:59











  • I figured out an iterative solution to my specific problem: I was trying to generate all subsets of a certain size for a given set. I do this iteratively now by incrementing a set of indices on the original set. I'll leave the question open though, since I think there are definitely algorithms where it's difficult to get an iterative solution.

    – rococo
    Mar 21 at 20:31






  • 1





    See e.g.jdoodle.com/a/15tZ, where I've generated an O(1) algorithm using iterators to generate each member of the Fibonacci sequence.

    – Alnitak
    Mar 21 at 20:32







  • 1





    stackoverflow.com/questions/931762/…

    – Alnitak
    Mar 21 at 20:33

















  • Check out my code here. May be this is what you are looking for, if not then at least could offer some hints.

    – Rahul R.
    Mar 21 at 19:13






  • 1





    Can you show an example of the recursive algorithm? Using iterators it's often possible to convert a recursive algorithm into an iterative one by retaining the state between calls to next().

    – Alnitak
    Mar 21 at 19:59











  • I figured out an iterative solution to my specific problem: I was trying to generate all subsets of a certain size for a given set. I do this iteratively now by incrementing a set of indices on the original set. I'll leave the question open though, since I think there are definitely algorithms where it's difficult to get an iterative solution.

    – rococo
    Mar 21 at 20:31






  • 1





    See e.g.jdoodle.com/a/15tZ, where I've generated an O(1) algorithm using iterators to generate each member of the Fibonacci sequence.

    – Alnitak
    Mar 21 at 20:32







  • 1





    stackoverflow.com/questions/931762/…

    – Alnitak
    Mar 21 at 20:33
















Check out my code here. May be this is what you are looking for, if not then at least could offer some hints.

– Rahul R.
Mar 21 at 19:13





Check out my code here. May be this is what you are looking for, if not then at least could offer some hints.

– Rahul R.
Mar 21 at 19:13




1




1





Can you show an example of the recursive algorithm? Using iterators it's often possible to convert a recursive algorithm into an iterative one by retaining the state between calls to next().

– Alnitak
Mar 21 at 19:59





Can you show an example of the recursive algorithm? Using iterators it's often possible to convert a recursive algorithm into an iterative one by retaining the state between calls to next().

– Alnitak
Mar 21 at 19:59













I figured out an iterative solution to my specific problem: I was trying to generate all subsets of a certain size for a given set. I do this iteratively now by incrementing a set of indices on the original set. I'll leave the question open though, since I think there are definitely algorithms where it's difficult to get an iterative solution.

– rococo
Mar 21 at 20:31





I figured out an iterative solution to my specific problem: I was trying to generate all subsets of a certain size for a given set. I do this iteratively now by incrementing a set of indices on the original set. I'll leave the question open though, since I think there are definitely algorithms where it's difficult to get an iterative solution.

– rococo
Mar 21 at 20:31




1




1





See e.g.jdoodle.com/a/15tZ, where I've generated an O(1) algorithm using iterators to generate each member of the Fibonacci sequence.

– Alnitak
Mar 21 at 20:32






See e.g.jdoodle.com/a/15tZ, where I've generated an O(1) algorithm using iterators to generate each member of the Fibonacci sequence.

– Alnitak
Mar 21 at 20:32





1




1





stackoverflow.com/questions/931762/…

– Alnitak
Mar 21 at 20:33





stackoverflow.com/questions/931762/…

– Alnitak
Mar 21 at 20:33












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287670%2fiterator-for-something-generated-recursively-without-pre-generating-the-results%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55287670%2fiterator-for-something-generated-recursively-without-pre-generating-the-results%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현