Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update console input example in section 4.6.1 #1

Open
klaeufer opened this issue Feb 5, 2018 · 3 comments
Open

update console input example in section 4.6.1 #1

klaeufer opened this issue Feb 5, 2018 · 3 comments

Comments

@klaeufer
Copy link
Member

klaeufer commented Feb 5, 2018

We need to update the import for newer versions of sbt, and it would be better to use Iterator instead of Stream to avoid the unnecessary memoization. The def is necessary to keep the iterator from starting until we want to see its values (by invoking next() directly or, as here, indirectly).

import jline.console.ConsoleReader
...
def it = Iterator.continually { reader.readLine("Prompt: ") }
val values = it.toList
@klaeufer klaeufer added the bug label Feb 5, 2018
@gkthiruvathukal
Copy link
Member

Thanks for this suggestion. Is this really a bug? I definitely agree it is better to use Iterator than Stream though. We also need to look at other examples using Stream, I think.

We should go through the entire tutorial and make sure it reflects our understanding of best current practices.

@klaeufer
Copy link
Member Author

klaeufer commented Feb 5, 2018

Well, there is a bug and a suboptimal use currently:

  • import no longer working
  • prepending a dummy item to Stream or Iterator is suboptimal

@gkthiruvathukal
Copy link
Member

Agreed on both counts, of course. The dummy value, however, was only needed because things don't work the way they should when I/O gets involved. It must be related to the problems you discovered with scanLeft().

We also need to clean up the Monte Carlo examples, etc. Those work fine with Stream.continually() but we now know better to use Iterator.

Thanks for reporting these so we keep it on radar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants