Scalaz has an asMA method, but no asIdentity method. The following produces a compilation error in Scala 2.9.1 as shown:
Some(0).max(None)
<console>:14: error: type mismatch;
found : None.type (with underlying type object None)
required: Ordering[?]
Some(0).max(None)
^
which can be fixed with an explicit cast:
(Some(0):Identity[Option[Int]]).max(None)
It seems to me that this would be more elegant, if asIdentity existed:
Some(0).asIdentity.max(None)
You can use the fact that
Identityhas aPureinstance:Note that you need to use
some(0)instead ofSome(0)here so that you start with something of typeOption[Int]instead ofSome[Int].There’s also
Identity.apply:Given these options—and the fact that explicitly indicating that you want to wrap something in
Identityis only necessary in a handful of cases like this, where you need to disambiguate—I’d guess the Scalaz designers just didn’t see the need for an additionalasIdentitymethod.