-
-
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
Build docs on 2.13 #4238
Build docs on 2.13 #4238
Changes from 1 commit
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 |
---|---|---|
|
@@ -102,29 +102,25 @@ which are lazy in their right hand argument to traverse the entire | |
structure unnecessarily. For example, if you have: | ||
|
||
```scala mdoc | ||
val allFalse = Stream.continually(false) | ||
val allFalse = LazyList.continually(false) | ||
``` | ||
|
||
which is an infinite stream of `false` values, and if you wanted to | ||
which is an infinite list of `false` values, and if you wanted to | ||
reduce this to a single false value using the logical and (`&&`). You | ||
intuitively know that the result of this operation should be | ||
`false`. It is not necessary to consider the entire stream in order to | ||
`false`. It is not necessary to consider the entire list in order to | ||
determine this result, you only need to consider the first | ||
value. Using `foldRight` from the standard library *will* try to | ||
consider the entire stream, and thus will eventually cause a stack | ||
overflow: | ||
consider the entire list, and thus will eventually cause an out-of-memory error: | ||
|
||
```scala mdoc | ||
try { | ||
allFalse.foldRight(true)(_ && _) | ||
} catch { | ||
case e:StackOverflowError => println(e) | ||
} | ||
```scala | ||
// beware! throws OutOfMemoryError, which is irrecoverable | ||
allFalse.foldRight(true)(_ && _) | ||
``` | ||
Comment on lines
-117
to
119
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 seemed to throw Problem is, unlike 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. Just to save time for other curious readers :) Specialized implementation of |
||
|
||
With the lazy `foldRight` on `Foldable`, the calculation terminates | ||
after looking at only one value: | ||
|
||
```scala mdoc | ||
Foldable[Stream].foldRight(allFalse, Eval.True)((a,b) => if (a) b else Eval.False).value | ||
Foldable[LazyList].foldRight(allFalse, Eval.True)((a,b) => if (a) b else Eval.False).value | ||
``` |
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 feels like a type inference regression from 2.12 -> 2.13.
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.
Yeah, seems so... I think it might be nice (in the future) to create a better version of
Writer.value
(andWriterT.value
) with some sort ofPartialApply
involved which would allow to write something line this: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.
Agree, we can do it bincompatibly probably but it would be source-breaking...