-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add getOrRaise for OptionT, EitherT and IorT #4212
Add getOrRaise for OptionT, EitherT and IorT #4212
Conversation
Thanks for the PR! Is this syntax the same ideas as def orRaise(other: => E)(implicit F: ApplicativeError[F, E]): F[A]
Edit: right, I see, you need the |
0410d24
to
bc395c6
Compare
@armanbilge |
I'm not currently working on anything, but it's an interesting idea and your PR reminded me of this problem :) I'm not sure if such a new idea could land in Cats due to the burden of guaranteeing long-term compatibility. However, I wonder if a 3rd party library can explore this idea by creating a |
Ha, that seems to be this: https://github.com/LukaJCB/cats-uio Maybe that repo just needs to be refreshed by an interested person :) |
I'll try to have a look, even just for Option and Either would be great! Especially when you have to deal with nested monads 😊 I see @LukaJCB already reached a great point there!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
I've recently opened and merged a PR for mouse adding
getOrRaise
method toF[Option[A]]
andF[Either[A, B]]
.typelevel/mouse#323
Since I found this method useful I'd like to introduce it to
OptionT
,EitherT
andIorT
.What do you think ?
P.S. For mouse, I've added
getOrRaiseMsg
as well which accepts aString
and lifts it toRuntimeException
.Honestly, I've always missed this feature in cats since in 99% of the cases I've seen this:
It would be great to have either
raiseErrorMsg
which accepts a stringraiseError
which accepts a stringException
likeval ex: RuntimeException = ex"ERROR"
in order to keep all other API unchanged