I don't understand exactly why this isn't working (and I've just asked a follow-up question about the part I don't understand), but I can offer three workarounds.
The first makes no sense to me and requires some deeper changes to your code and clunky syntax, so I'll only mention it in passing.
The second is to import the appropriate FunctorSyntax
implicits (as opposed to the ToFunctorOps
ones that aren't working properly):
scala> val of = implicitly[scalaz.Functor[Option]]
of: scalaz.Functor[Option] = scalaz.std.OptionInstances$$anon$1@377d4c39
scala> import of.functorSyntax._
import of.functorSyntax._
scala> 1.some |> (inc _).lift
res0: Option[Int] = Some(2)
But this requires you to import these implicits for every individual Functor
you want to use them with, and isn't much better than just writing of lift inc
.
The last requires a little more code but is more satisfying. You need the following new syntax trait, with a myLift
method modeled of the lift
in Function2Ops
:
trait MyFunction1Syntax[A, R] extends scalaz.syntax.Ops[A => R] {
def myLift[F[_]](implicit F: scalaz.Functor[F]) = F lift self
}
implicit def toMyFunction1Syntax[A, R](f: A => R) =
new MyFunction1Syntax[A, R] { def self = f }
And now you can write the following:
scala> 1.some |> (inc _).myLift
res3: Option[Int] = Some(2)
It might be worth bringing this issue up on the Scalaz mailing list.