Cats: Add `or` to ApplicativeError

Created on 2 May 2018  路  7Comments  路  Source: typelevel/cats

def or(other: IO[A]): IO[A] = io.attempt.flatMap {
    case Right(a) => IO.pure(a)
    case Left(e)  => other
 }

Also, this implies you can make a SemigroupK if you have a MonadError. With an example error, you can make a MonoidK. Or, if you have a MonadError[F, Unit], such as Option, you have an Alternative, I guess.

help wanted low-hanging fruit

Most helpful comment

@barambani Please!

All 7 comments

see: https://github.com/getnelson/nelson/pull/64/files#diff-7a41efcf4f5af17c787bac91073f6fe7R68

we can add this to ApplicativeErrorOps in 1.x.

true, handleErrorWith is all that is needed here.

I could look into this if that's ok

@barambani Please!

@kailuowang do we have a list of changes that we hacked onto AnyVal classes that we would like to undo?

Side question: should we prefer to keep typeclasses minimal, and have most methods on anyval extensions? It seems that we have almost all methods on the typeclass rather than thinking much about what could plausibly be optimized per type. I guess if binary compatibility was not a problem, and it won't be in 2.12, putting on the trait is strictly better. Maybe we just need to get the community to move to 2.12.

@johnynek we don't have a list. I suppose when we move to a 2.12 only version we should review all these AnyVal classes and move the implementations of appropriate ones to the traits along with some "consistency" laws. It's shame that the community couldn't benefit from the better binary compat support from 2.12. Hopefully, now the ScalaCenter is helping, Spark can move over soon.

Was this page helpful?
0 / 5 - 0 ratings