I came across a puzzling, but interesting, code construct that I whittled down to a small example, and that I still have trouble wrapping my head around.
The example is shown below. Note that I have a simple Future that immediately returns a String. I map this to a comparison of the Future itself using != and ==
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
object Dummy extends App {
val taskReturningString: Future[String] = Future{ "foo"}
val falseResult: Future[Boolean] = taskReturningString.map(taskReturningString ==)
System.out.println("false result:" + Await.result(falseResult, 0 nanos) )
val trueResult: Future[Boolean] = taskReturningString.map(taskReturningString !=)
System.out.println("true result:" + Await.result(trueResult, 0 nanos) )
}
The output is
false result:false
true result:true
But I'm not sure why I got those results. In the case of ==, and != the first item being compared is 'taskReturningString' -- the Future. But what is it being compared to ? I am assuming that what is happening is a comparison, but I've never seen a case where the operators == and != appear with one operand instead of two.