scala / docs.scala-lang

The Scala Documentation website
http://docs.scala-lang.org
561 stars 1.02k forks source link

Examples (lots of) with a broken sense of FP #2315

Open ac2epsilon opened 2 years ago

ac2epsilon commented 2 years ago
i match
  case 0 => println("1")
  case 1 => println("2")
  case what => println(s"You gave me: $what" )

While things like this just work, far better from the beginning insulate pure (adt) code from impure (smelling) one. Sure the following interpretation is more Scal-ish than the former, simplifies refactoring, and after all saves typing:

val r = i match
  case 0 => "1"
  case 1 => "2"
  case what => s"You gave me: $what"
println(r)
julienrf commented 2 years ago

That’s a good point, thank you for creating this issue. Would you be interested in submitting a fix?

ac2epsilon commented 2 years ago

Good, it's mine, then.

Not a fix actually, it is rather some code review.

Codename un-print-l-n-isation(-itation?). I will use it to mark all related PRs. Any suggestions?

To hold control I limit the scope to Scala 3 book.

The plan is the following: open files in order, look for println, paraphrase code to remove println-s (but one), try in Scastie, commit in loop, push, PR in loop.

Looks like a simple bot's job.

I expect to spend some days/couple of weeks on this in relaxed mode. To avoid the all-or-nothing case I will pack some commits/files processed into single PR and so forth.

Does it all of this relevant and adequate?

Also, I sent some other ideas, but as they say, let's one thread at a time.

Message ID: @.***>

julienrf commented 2 years ago

I don't think we should systematically remove all the println statements. In the example you gave, that would improve the readability (although I would rename the val to 'message' instead of 'r'), with the added benefit of showing a purely functional match expression.

ac2epsilon commented 2 years ago

Got it. Working.

вт, 8 лют. 2022 р. о 09:04 Julien Richard-Foy @.***> пише:

I don't think we should systematically remove all the println statements. In the example you gave, that would improve the readability (although I would rename the val to 'message' instead of 'r'), with the added benefit of showing a purely functional match expression.

— Reply to this email directly, view it on GitHub https://github.com/scala/docs.scala-lang/issues/2315#issuecomment-1032275556, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACGYFUHTUJ76A2PXCOMHLRDU2C56XANCNFSM5NTQFGUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>