Scalaz minimal imports required to inject right and left use
scala, scalaz
Solution
`syntax.id` contains syntax for "plain" values, i.e. it places no constraints on the type of the value.
In general, when you import syntax for an expression of the form `x.op`, the place to import the syntax depends on the type of `x`, because `op` needs to be a valid operation on that type.
Because `\/[A, B]` is universally quantified for A and B, using the syntax `x.left` and `x.right` places no constraints on the type of `x`. Hence, it belongs in `syntax.id`.
For a working understanding of what syntax is available where, it is worth looking at the source of some of the modules that make up the `syntax` packages. For example, contrast `IdOps[A]`, which has syntax for any `A`, with `FunctorOps[F[_],A]`, which has the requirement that `F` is a `Functor`.
I am not sure where the name `id` comes from exactly; perhaps it is related to the identity functor `Id`, which can be defined as `type Id[A] = A`. If you had to choose a type constraint for values usable with `syntax.id`, it would be that they are in `Id`. Being universally quantified in `A`, the operations can't know about the structure of a value of `A`, hence they can't be structure-altering operations on `A`.
Problem
Simple question, I have looked at this one already: Managing imports in Scalaz7, but I can't figure out how to minimally inject the `right` and `left` methods into my objects to construct instances of `\/`. I did try: `import syntax.ToDataOps` and other variations of `To...` such as `syntax.ToIdOps` as suggested in http://eed3si9n.com/learning-scalaz-day13. Simple example: ``` import scalaz.{\/, syntax} import // What goes here class Test { def returnEitherT(h: Int): String \/ Int = { h right } } ``` Thanks, Jason. =========== I solved it by using `import syntax.id._` but I'm unsure why this worked.