Why does the following equality comparison result in false?
$scala
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_51).
scala> import scala.concurrent.Future
import scala.concurrent.Future
scala> Future.successful(5) == Future.successful(5)
res4: Boolean = false
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
val fa = Future successful 5val fb = Future successful 5val result = for(a <- fa; b <- fb) yield a == b
val result = fa flatMap {a => fb map (a == _) }
Expanding on that, the only valid comparison between Futures would itself be asynchronous, so you're looking for a Future[Boolean]As in...val fa = Future successful 5val fb = Future successful 5val result = for(a <- fa; b <- fb) yield a == borval result = fa flatMap {a => fb map (a == _) }Personally, I prefer the first form... though it could be argued that it's a tiny bit less efficient
On 30 August 2015 at 12:35, Viktor Klang <viktor...@gmail.com> wrote:Nils is on the right track, but it's not due to its statefulness (already completed Futures are immutable values), it is due to the temporal aspect of Futures.On Sun, Aug 30, 2015 at 6:12 AM, Nils Kilden-Pedersen <nil...@gmail.com> wrote:Probably because a Future is stateful, thus any such comparison is inherently indeterministic.On Sat, Aug 29, 2015 at 10:30 PM, Kevin Meredith <kevin.m....@gmail.com> wrote:Why does the following equality comparison result in false?
$scala
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_51).
scala> import scala.concurrent.Future
import scala.concurrent.Future
scala> Future.successful(5) == Future.successful(5)
res4: Boolean = false
On Sun, Aug 30, 2015 at 1:48 PM, Kevin Wright <kev.lee...@gmail.com> wrote:Expanding on that, the only valid comparison between Futures would itself be asynchronous, so you're looking for a Future[Boolean]As in...val fa = Future successful 5val fb = Future successful 5val result = for(a <- fa; b <- fb) yield a == borval result = fa flatMap {a => fb map (a == _) }Personally, I prefer the first form... though it could be argued that it's a tiny bit less efficientAlso, note that the above doesn't consider failed Futures with equal exceptions as equal.
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.