-
-
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
added a new foldRight lazy law, move forallLazy and existLazy laws #2817
Changes from 6 commits
b9b8144
70d513f
d6b1584
5811126
1e9fcd7
f75c18a
cc8f633
fbc7cf8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,24 +21,6 @@ trait UnorderedFoldableLaws[F[_]] { | |
(F.isEmpty(fa) || F.exists(fa)(p)) | ||
} else true // can't test much in this case | ||
|
||
def existsLazy[A](fa: F[A]): Boolean = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Foldable extends UnorderedFoldable. To me, the bug here is that we weren’t calling these in UnorderedFoldable tests and that FoldableLaws were not calling through to them as we should do any time we extend a typeclass. That seems like the better fix to me than moving the law (since we should still want these laws on UnorderedFoldable). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does look that way but actually the default implementations of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can keep the laws in |
||
var i = 0 | ||
F.exists(fa) { _ => | ||
i = i + 1 | ||
true | ||
} | ||
i == (if (F.isEmpty(fa)) 0 else 1) | ||
} | ||
|
||
def forallLazy[A](fa: F[A]): Boolean = { | ||
var i = 0 | ||
F.forall(fa) { _ => | ||
i = i + 1 | ||
false | ||
} | ||
i == (if (F.isEmpty(fa)) 0 else 1) | ||
} | ||
|
||
/** | ||
* If `F[A]` is empty, forall must return true. | ||
*/ | ||
|
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 use += here but not below. Any reason for the difference?
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.
no real reason except this one is written by me and the other ones are from before. Just changed the other ones to be more consistent.