Is there a Scala Or really a Monad
Yes, it really is - otherwise it would be in a skalase-outlaw. Either
bind
is defined as follows:
trait Either[A, B] {
def bind[C](f: B => Either[A, C]) = this match {
case Right(b) => f(b)
case Left(a) => Left(a)
}
}
(in practice it is defined with a typeclass, but the above definition will work)
I suppose it's more correct to say that for a fixed A
type ({type L[B]=Either[A, B]})#L
forms a Monad
, so it Either
is more of a class Monads
than a Monad
in its own right, but this is an extremely technical distinction.
But it really is Monad
; it satisfies all the laws of the monad.
source to share