@@ -241,6 +241,11 @@ private[data] abstract class XorTInstances1 extends XorTInstances2 {
241241}
242242
243243private [data] abstract class XorTInstances2 extends XorTInstances3 {
244+ implicit def xorTMonadRec [F [_], L ](implicit F0 : MonadRec [F ]): MonadRec [XorT [F , L , ? ]] =
245+ new XorTMonadRec [F , L ] { implicit val F = F0 }
246+ }
247+
248+ private [data] abstract class XorTInstances3 extends XorTInstances4 {
244249 implicit def xorTMonadError [F [_], L ](implicit F : Monad [F ]): MonadError [XorT [F , L , ? ], L ] = {
245250 implicit val F0 = F
246251 new XorTMonadError [F , L ] { implicit val F = F0 }
@@ -261,7 +266,7 @@ private[data] abstract class XorTInstances2 extends XorTInstances3 {
261266 }
262267}
263268
264- private [data] abstract class XorTInstances3 {
269+ private [data] abstract class XorTInstances4 {
265270 implicit def xorTFunctor [F [_], L ](implicit F : Functor [F ]): Functor [XorT [F , L , ? ]] = {
266271 implicit val F0 = F
267272 new XorTFunctor [F , L ] { implicit val F = F0 }
@@ -273,10 +278,13 @@ private[data] trait XorTFunctor[F[_], L] extends Functor[XorT[F, L, ?]] {
273278 override def map [A , B ](fa : XorT [F , L , A ])(f : A => B ): XorT [F , L , B ] = fa map f
274279}
275280
276- private [data] trait XorTMonadError [F [_], L ] extends MonadError [XorT [F , L , ? ], L ] with XorTFunctor [F , L ] {
281+ private [data] trait XorTMonad [F [_], L ] extends Monad [XorT [F , L , ? ]] with XorTFunctor [F , L ] {
277282 implicit val F : Monad [F ]
278283 def pure [A ](a : A ): XorT [F , L , A ] = XorT .pure[F , L , A ](a)
279284 def flatMap [A , B ](fa : XorT [F , L , A ])(f : A => XorT [F , L , B ]): XorT [F , L , B ] = fa flatMap f
285+ }
286+
287+ private [data] trait XorTMonadError [F [_], L ] extends MonadError [XorT [F , L , ? ], L ] with XorTMonad [F , L ] {
280288 def handleErrorWith [A ](fea : XorT [F , L , A ])(f : L => XorT [F , L , A ]): XorT [F , L , A ] =
281289 XorT (F .flatMap(fea.value) {
282290 case Xor .Left (e) => f(e).value
@@ -295,6 +303,16 @@ private[data] trait XorTMonadError[F[_], L] extends MonadError[XorT[F, L, ?], L]
295303 fla.recoverWith(pf)
296304}
297305
306+ private [data] trait XorTMonadRec [F [_], L ] extends MonadRec [XorT [F , L , ? ]] with XorTMonad [F , L ] {
307+ implicit val F : MonadRec [F ]
308+ def tailRecM [A , B ](a : A )(f : A => XorT [F , L , A Xor B ]): XorT [F , L , B ] =
309+ XorT (F .tailRecM(a)(a0 => F .map(f(a0).value){
310+ case Xor .Left (l) => Xor .Right (Xor .Left (l))
311+ case Xor .Right (Xor .Left (a1)) => Xor .Left (a1)
312+ case Xor .Right (Xor .Right (b)) => Xor .Right (Xor .Right (b))
313+ }))
314+ }
315+
298316private [data] trait XorTMonadFilter [F [_], L ] extends MonadFilter [XorT [F , L , ? ]] with XorTMonadError [F , L ] {
299317 implicit val F : Monad [F ]
300318 implicit val L : Monoid [L ]
0 commit comments