-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
whenA
and unlessA
by-name makes syntax inconsistent with typeclass
#3687
Comments
This is fixable but keeping bincompat is complicated |
how to fix is also up for debate, and hinges on some I think fundamental aspects of what cats aims to do, which I want to stress is different from cats-effect. As an example
|
I tend to think of by-name as being justified only when we're expecting users to apply combinators in recursive contexts and the combinator implements internal branching. In this case, Conversely, |
But it does implement internal branching: def whenA[A](cond: Boolean)(f: => F[A]): F[Unit] =
if (cond) void(f) else unit |
Oooooh I was thinking of ifA. So then yeah, if it's commonly expected to be used in a recursive context, then I think the laziness is justified. |
Applicative.whenA
andApplicative.unlessA
are defined using a by-name argument. Syntax extension is via a value-class though which naturally can't use a by-name in it's constructor. This means that callingwhenA
is either eager or lazy depending on whether it is called from the typeclass (lazy) or the syntax (eager).Definition:
Syntax:
I had a brief discussion with @SystemFw (sorry for ping!) on gitter and they suggested opening the issue as it's a messy problem.
The text was updated successfully, but these errors were encountered: