Skip to content

Add F[Boolean] syntax#4114

Closed
BalmungSan wants to merge 1 commit into
typelevel:mainfrom
BalmungSan:add-boolean-syntax
Closed

Add F[Boolean] syntax#4114
BalmungSan wants to merge 1 commit into
typelevel:mainfrom
BalmungSan:add-boolean-syntax

Conversation

@BalmungSan

Copy link
Copy Markdown
Contributor

I know that, in general, we prefer to avoid F[Boolean] but sometimes we have those values and I personally think this syntax can be very useful.

Let me know what you think about this change and the Scaladoc (I couldn't come up with something better).
Also, for testing this change I could only think on a simple truth table but I am not sure if that is a good test.

@rossabaker

Copy link
Copy Markdown
Member

There's no clear line between the two, but a lot of syntactic convenience goes in mouse instead of cats. Might this fit better there?

@BalmungSan

BalmungSan commented Jan 21, 2022

Copy link
Copy Markdown
Contributor Author

I renamed and & or to andM & orM per recommendation from Rob in the discord server.

I also removed xor since I think the main selling point of this addition is preserving the laziness that most folks expect of and & or which you lose with the typical advice of (fa, fb).mapN(_ && _)


I will wait a little bit more before deciding to close this and move it to mouse as per Ross suggestion.

Comment thread core/src/main/scala/cats/syntax/monad.scala
/**
* Behaves like `||` but inside the `F` context.
*
* Wont evaluate `other` unless this evaluates to `false`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is wrong. Also underscores the need for tests.

@BalmungSan BalmungSan Jan 21, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Care to elaborate on why that is wrong?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or returns true if either are true. This returns false if the first is true.

@BalmungSan BalmungSan Jan 21, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ups... that happens for copypasting code 😅
I am sorry for that.

Yeah, I agree tests are good, but then again how should I test them? The truth tables?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would say that for all pairs of inputs Id[Boolean] ops should behave like the normal ops on Boolean, which yes is equivalent to testing the truth table.

}

final class MonadBooleanOps[F[_]](private val fa: F[Boolean]) extends AnyVal {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

She we also add nand, nor, any, all?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since it seems that and and or are already niche enough that most folks seem to be against this addition, I doubt there is value on those others.

IMHO, these two are useful enough to be on cats but that is up to the consensus of everyone.

@danicheg danicheg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with @rossabaker that https://github.com/typelevel/mouse is a probably better place for that syntax. Mouse already has some F[Foo] syntax, so it would be natural to have F[Boolean] syntax too.

@BalmungSan

Copy link
Copy Markdown
Contributor Author

Moved to mouse based on feedback.
typelevel/mouse#297

@BalmungSan BalmungSan closed this Jan 23, 2022
@BalmungSan
BalmungSan deleted the add-boolean-syntax branch January 23, 2022 00:15
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.

5 participants