You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ scala -WunusedWelcome to Scala2.13.2 (OpenJDK64-BitServerVM, Java1.8.0_252).
Type in expressions for evaluation. Ortry:help.
scala>:paste
// Entering paste mode (ctrl-D to finish)valoptA:Option[Int] =Option(42)
valoptB:Option[Int] =Option(0)
valx1:Option[Int] =for {
a <- optA
b <- optB
if a != b
} yield a
// Exiting paste mode, now interpreting.
b <- optB
^
<pastie>:6:warning: parameter value b in anonymous function is never used
valoptA:Option[Int] =Some(42)
valoptB:Option[Int] =Some(0)
valx1:Option[Int] =Some(42)
problem
It gives the warning because b is not used in yield. Still, it is used in if a != b. I guess that for comprehension is desugared more or less in:
optA.flatMap { a =>
optB.withFilter(b => a != b).map(b => a)
}
Instead it should be desugared in the following one in order not to get the warning:
optA.flatMap { a =>
optB.withFilter(b => a != b).map(_ => a)
}
The text was updated successfully, but these errors were encountered:
reproduction steps
using Scala 2.13.2,
problem
It gives the warning because
b
is not used in yield. Still, it is used inif a != b
. I guess that for comprehension is desugared more or less in:Instead it should be desugared in the following one in order not to get the warning:
The text was updated successfully, but these errors were encountered: