Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a convenient shorthand for predicating effects on a boolean signal. #2596

Merged
merged 2 commits into from
Sep 10, 2021

Conversation

mn98
Copy link
Contributor

@mn98 mn98 commented Sep 7, 2021

Purely for convenience, this allows for writing
signal.predicate(f)
instead of
signal.get.flatMap(f.whenA)


/** Predicate the supplied effect `f` on this `Signal` being `true`.
*/
def predicate(f: F[_])(implicit F: Applicative[F] with FlatMap[F]): F[Unit] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def predicate(f: F[_])(implicit F: Applicative[F] with FlatMap[F]): F[Unit] =
def predicate(f: F[_]: Monad): F[Unit] =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that form doesn't compile for me, but this form does:
def predicate(f: F[_])(implicit F: Monad[F]): F[Unit]
Is that ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, yep

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great; committed.

@mn98
Copy link
Contributor Author

mn98 commented Sep 10, 2021

I would add that although this is a minor convenience feature it's probably still worth merging. I get the impression much of the *Ops sugar will eventually move out to a separate module/project, which would then include this little gem. I probably wouldn't have raised this PR if BooleanSignalOps didn't already exist.

@mpilquist mpilquist merged commit a7a6370 into typelevel:main Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants