monad 转换器XorT
继承自MonadError
暴露错误处理功能。我想为它创建一个MonadError
类型类的实例,WriterT[XorT ...]
但我没有实现该handleErrorWith
方法。
type WriterValid[L, E, T] = WriterT[XorT[Id, E, ?], L, ?]
val writerValidMonad = new MonadError[WriterValid[L, E, ?], E] {
private val monadT = data.WriterT.writerTMonad[XorT[Id, E, ?], L]
def raiseError[A](e: E): WriterValid[L, E, A] =
cats.data.WriterT[Valid[E,?],L,A](validMonad.raiseError[(L,A)](e))
def handleErrorWith[A](fa: WriterValid[L, E, A])(f: (E) => WriterValid[L, E, A]): WriterValid[L, E, A] =
???
def pure[A](x: A): WriterValid[L, E, A] =
monadT.pure(x)
def flatMap[A, B](fa: WriterValid[L, E, A])(f: (A) => WriterValid[L, E, B]): WriterValid[L, E, B] =
monadT.flatMap(fa)(f)
}
这是可以轻松完成的事情吗?这也是创建MonadError
实例的最佳方法吗?