-
-
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
Add Defer.fix #3208
Add Defer.fix #3208
Changes from 2 commits
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 |
---|---|---|
|
@@ -46,6 +46,22 @@ class FunctionSuite extends CatsSuite { | |
// TODO: make an binary compatible way to do this | ||
// checkAll("Function1[Int => *]", DeferTests[Function1[Int, *]].defer[Int]) | ||
|
||
test("Defer[Function1[Int, *]].fix computing sum") { | ||
val sum2 = Defer[Function1[Int, *]].fix[Int] { | ||
rec => | ||
{ n: Int => | ||
if (n <= 0) 0 else n * n + rec(n - 1) | ||
} | ||
} | ||
|
||
forAll { n0: Int => | ||
val n = n0 & 0x3FF // don't let it get too big | ||
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. This is nitpicky but could you just write this out for clarity? I can't remember off the top of my head what this does for negative 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's taking the 18 least significant bits. Perhaps a slightly clearer way to write it for those who aren't doing bit manipulation on a regular basis would be 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. I've changed it to be more direct |
||
assert(sum2(n) == (0 to n).map { n => | ||
n * n | ||
}.sum) | ||
} | ||
} | ||
|
||
checkAll("Semigroupal[Function1[Int, *]]", SerializableTests.serializable(Semigroupal[Function1[Int, *]])) | ||
|
||
checkAll("Function1[MiniInt, Int]", MonadTests[MiniInt => *].monad[Int, Int, Int]) | ||
|
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.
This is rather nice! I never knew I wanted this.