Skip to content

Tidy comments in ByNameParameter.scala #189

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

Merged
merged 1 commit into from
May 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/scala/stdlib/ByNameParameter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ object ByNameParameter
def takesUnitByNameParameter(res0: Either[Throwable, Int]) = {
def calc(x: () => Int): Either[Throwable, Int] = {
try {
Right(x()) //An explicit call of the x function
Right(x()) // An explicit call of the x function
} catch {
case b: Throwable => Left(b)
}
}

val y = calc { () => //Having explicitly declaring that Unit is a parameter with ()
val y = calc { () => // explicitly declaring that Unit is a parameter with ()
14 + 15
}

Expand All @@ -48,7 +48,7 @@ object ByNameParameter
*/
def byNameParameter(res0: Either[Throwable, Int]) = {
def calc(x: => Int): Either[Throwable, Int] = {
//x is a call by name parameter
// x is a call by-name parameter
try {
Right(x)
} catch {
Expand All @@ -57,16 +57,16 @@ object ByNameParameter
}

val y = calc {
//This looks like a natural block
println("Here we go!") //Some superfluous call
val z = List(1, 2, 3, 4) //Another superfluous call
// This looks like a natural block
println("Here we go!") // Some superfluous call
val z = List(1, 2, 3, 4) // Another superfluous call
49 + 20
}

y should be(res0)
}

/** By name parameters can also be used with `object` and `apply` to make interesting block-like calls:
/** By-name parameters can also be used with `object` and `apply` to make interesting block-like calls:
*/
def withApplyByNameParameter(res0: String) = {
object PigLatinizer {
Expand Down