What is the use of this scalaz.Ordering case?

Reading http://eed3si9n.com/learning-scalaz/Order.html :

scala> 1.0 ?|? 2.0
res10: scalaz.Ordering = LT

      

Everything that is stated in relation to the order:

"

scala> 1 > 2.0
res8: Boolean = false

scala> 1 gt 2.0
<console>:14: error: could not find implicit value for parameter F0: scalaz.Order[Any]
              1 gt 2.0
              ^

scala> 1.0 ?|? 2.0
res10: scalaz.Ordering = LT

scala> 1.0 max 2.0
res11: Double = 2.0

Order enables ?|? syntax which returns Ordering: LT, GT, and EQ. It also enables lt, gt, lte, gte, min, and max operators by declaring order method. Similar to Equal, comparing Int and Doubl fails compilation.

      

"

What is the meaning of scalaz.Ordering in this case?

1.0 max 2.0 uses the standard Scala API max method and is not scalaz?

+3


source to share


2 answers


Scalaz provides this syntax for instance things Order

. You are correct in this case, which 1.0 max 2.0

will use max

from the standard library, however, since it is more specific (as you can quickly confirm by powering up with the :power

REPL and then typing something for example settings.processArgumentString("-print typer")

).



The best example in this case would be something like some(2.0) max some(1.0)

, since the standard library does not provide max

for Option[Double]

that hiding Scalaz's.

+4


source


Tom Switzer summarizes in a related thread :



Instead of returning Int

from Order#compare

, scalaz returns scalaz.Ordering

.

0


source







All Articles