@@ -77,6 +77,36 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
7777 override def map [B , C ](fa : Either [A , B ])(f : B => C ): Either [A , C ] =
7878 fa.map(f)
7979
80+ override def as [B , C ](fa : Either [A , B ], c : C ): Either [A , C ] =
81+ fa match {
82+ case Right (_) => Right (c)
83+ case left @ Left (_) => left.rightCast[C ]
84+ }
85+
86+ override def tupleLeft [B , C ](fa : Either [A , B ], c : C ): Either [A , (C , B )] =
87+ fa match {
88+ case Right (b) => Right ((c, b))
89+ case left @ Left (_) => left.rightCast[(C , B )]
90+ }
91+
92+ override def tupleRight [B , C ](fa : Either [A , B ], c : C ): Either [A , (B , C )] =
93+ fa match {
94+ case Right (b) => Right ((b, c))
95+ case left @ Left (_) => left.rightCast[(B , C )]
96+ }
97+
98+ override def fproduct [B , C ](fa : Either [A , B ])(f : B => C ): Either [A , (B , C )] =
99+ fa match {
100+ case Right (b) => Right ((b, f(b)))
101+ case left @ Left (_) => left.rightCast[(B , C )]
102+ }
103+
104+ override def fproductLeft [B , C ](fa : Either [A , B ])(f : B => C ): Either [A , (C , B )] =
105+ fa match {
106+ case Right (b) => Right ((f(b), b))
107+ case left @ Left (_) => left.rightCast[(C , B )]
108+ }
109+
80110 @ tailrec
81111 def tailRecM [B , C ](b : B )(f : B => Either [A , Either [B , C ]]): Either [A , C ] =
82112 f(b) match {
@@ -210,6 +240,12 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances {
210240 }
211241 }
212242
243+ override def unzip [B , C ](fab : Either [A , (B , C )]): (Either [A , B ], Either [A , C ]) =
244+ fab match {
245+ case Right ((b, c)) => (Right (b), Right (c))
246+ case left @ Left (_) => (left.rightCast[B ], left.rightCast[C ])
247+ }
248+
213249 override def void [B ](e : Either [A , B ]): Either [A , Unit ] =
214250 if (e.isRight) Either .unit
215251 else e.asInstanceOf [Either [A , Unit ]] // it is Left(a)
0 commit comments