-
Notifications
You must be signed in to change notification settings - Fork 530
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
Updated tutorial to new doc site + CE 3.0.0-RC2 #1799
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely amazing! Thank you for tackling this! It was on my todo list, but my todo list is massive at this point…
Quick question: can we adjust the code snippets to build with mdoc so that they don't go stale?
guard <- Semaphore[IO](1) | ||
count <- inputOutputStreams(origin, destination, guard).use { case (in, out) => | ||
guard.permit.use { _ => | ||
transfer(in, out) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be more clear to rewrite this in the following fashion?
val rsrc = for {
guard <- Resource.eval(Semaphore[IO](1))
_ <- inputOutputStreams(origin, destination, guard)
_ <- guard.permit
count <- Resource.eval(transfer(in, out))
} yield count
rsrc.use(IO.pure(_))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... it's undeniably more elegant, but I'm having trouble myself reading the code (sorry :) ), I guess other newcomers can find it also a bit daunting. Also, it doesn't compile... I think I get the idea but I'd need to refactor the code to make it work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't mind I'd rather let the code as it's now. I still think it will be easier for people with little or no experience with CE. Also, the change would require some substantial rewrite I think :/ .
docs/tutorial.md
Outdated
orig = new File(args(0)) | ||
dest = new File(args(1)) | ||
count <- copy(orig, dest) | ||
_ <- Console[IO].println(s"$count bytes copied from ${orig.getPath} to ${dest.getPath}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IO.println
also works. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! But there are Console[IO].errorln
calls in the snippets while there is no IO.errorln
. So for the sake of homogeneity I wasn't sure what to do here. I'll change it and explain that IO.println
is just Console[IO].println
underneath.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally fair!
docs/tutorial.md
Outdated
WARNING: To properly test cancelation, You should also ensure that | ||
`fork := true` is set in the sbt configuration, otherwise sbt will | ||
intercept the cancelation because it will be running the program | ||
in the same JVM as itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning should not be required any longer since IOApp
detects this scenario and does the Right Thing™
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Removing the warning then 👍
docs/tutorial.md
Outdated
_ <- if(iO.exists(_ % 10000 == 0)) Console[F].println(s"Consumed ${iO.get} items") else Sync[F].unit | ||
} yield ()) >> consumer(queueR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just recommend better-monadic-for so we can pull the consumer(queueR)
into the for
-comprehension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact I put the recursive call outside the for
so it's easily spotted by the reader. Like, 'this is the main thing to do and then we start all over again'. But if you think it would be actually clearer putting the recursive call inside the for
I'd be happy to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's kind of a stylistic thing. IMO I prefer having it inside, the same way it would be if you were writing something like this in an imperative style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No prob then, changing it 👍
Glad to help :) , sorry I didn't undertake this sooner. No prob on using mdoc, but I have never used it before. Any modifier I should use? |
I think so? My knowledge of mdoc rounds to zero. :-D @keynmol might have some suggestions |
@lrodero given that the docs/ folder should'be already covered by mdoc, then yeah, changing all your snippets (apart from SBT ones) from
to
Will make sure they're compiled along with the code, but they won't be executed (which for bare IO means nothing without unsafeRunSync or using a special modifier Couple of points:
|
And your magic SBT watch command for gradually updating the tutorial is:
(mdoc has its own watch mode for inputs) |
Thanks for the tips @keynmol ! Ok I think I got it. Two things to note:
|
Updated tutorial for CE
3.0.0-RC2
. Changes to note:std/Queue.scala
.build.sbt
in the text points to3.0.0-RC2
. As soon as final version is released I can prepare a small change so it points to3.0.0
.This new version of the tutorial can be read here.
Code samples used in the tutorial are available here.