-
-
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 OptionT
combinators for effectful Boolean
#4390
Conversation
def whenM[F[_], A](cond: F[Boolean])(fa: => F[A])(implicit F: Monad[F]): OptionT[F, A] = OptionT( | ||
F.ifM(cond)(ifTrue = F.map(fa)(Some(_)), ifFalse = F.pure(None)) | ||
) |
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.
Just to note: although there's nothing particularly wrong with this method, however I think it might not be as useful as it might seem at first glance. Just because it does not allow monads chaining. I.e. if a chain of F[_]
ends with F[Boolean]
then the entire chain has to be enwrapped into whenF
to lift the result into OptionT
.
I think, a better approach could be adding an extension method for F[Boolean]
itself. And there's a good place for it already:
mouse / fboolean.scala. E.g. it could be a new extension method of type
F[Boolean] => F[A] => F[Option[A]]
then there's another method liftOptionT
in there mouse / foption.scala
that can also be applied aferwards.
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.
we already have when and whenF. In my personal opinion, I think it is fine to add it here.
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.
Yep, no objections either.
I went ahead and approved, but the optimization of avoiding the |
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!
OptionT
combinators for effectful Boolean
Thanks for this PR! |
OptionT[F, A].filterF(p: A => F[Boolean])
to filter on effectful F[Boolean]OptionT.whenM[F[_], A](fp: F[Boolean])(a: => F[A])
to construct based on effectful F[Boolean]