Skip to content
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

Increase laziness of LazyList.cons.apply #9095

Merged
merged 1 commit into from Jul 2, 2020

Conversation

NthPortal
Copy link
Contributor

@NthPortal NthPortal commented Jul 1, 2020

Change LazyList.cons.apply so that the tail computation
is wrapped as a state computation for a new LazyList,
thus deferring its execution as long as possible.

Follow-up to #8985


Before (Scala 2.13.3-):

scala 2.13.3> LazyList.cons(1, { println("hey"); LazyList() })
val res6: scala.collection.immutable.LazyList[Int] = LazyList(<not computed>)

scala 2.13.3> res6.head
hey
val res7: Int = 1

After (Scala 2.13.4+):

scala 2.13.4> LazyList.cons(1, { println("hey"); LazyList() })
val res6: scala.collection.immutable.LazyList[Int] = LazyList(<not computed>)

scala 2.13.4> res6.head
val res7: Int = 1

@NthPortal NthPortal added the library:collections PRs involving changes to the standard collection library label Jul 1, 2020
@scala-jenkins scala-jenkins added this to the 2.13.4 milestone Jul 1, 2020
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Jul 1, 2020
@@ -693,6 +693,20 @@ class LazyListLazinessTest {
assertLazyAllSkipping(op, 4)
}

private def genericCons_unapply_properlyLazy(unapply: LazyList[Int] => Option[(Int, LazyList[Int])]): Unit = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed there were no tests for these while I was in the area, so I added tests

@NthPortal NthPortal merged commit 9208bc4 into scala:2.13.x Jul 2, 2020
@NthPortal NthPortal deleted the topic/ll-again branch July 2, 2020 10:23
ijuma added a commit to ijuma/scala-library-compat that referenced this pull request Jul 5, 2020
Port of scala/scala#9095.

Co-authored-by: NthPortal <nthportal@gmail.com>
ijuma added a commit to ijuma/scala-library-compat that referenced this pull request Jul 5, 2020
Port of scala/scala#9095.

Co-authored-by: NthPortal <nthportal@gmail.com>
ijuma added a commit to ijuma/scala-library-compat that referenced this pull request Jul 5, 2020
Port of scala/scala#9095.

Co-authored-by: NthPortal <nthportal@gmail.com>
ijuma added a commit to ijuma/scala-library-compat that referenced this pull request Jul 5, 2020
Port of scala/scala#9095.

Co-authored-by: NthPortal <nthportal@gmail.com>
ijuma added a commit to ijuma/scala-library-compat that referenced this pull request Aug 24, 2020
Port of scala/scala#9095.

Co-authored-by: NthPortal <nthportal@gmail.com>
@SethTisue
Copy link
Member

SethTisue commented Nov 17, 2020

@NthPortal would you mind improving the PR title and description to be at least a little more informative for end users? since we're linking to this from the 2.13.4 release notes

perhaps you can borrow some verbiage from the discussion on #8985

@NthPortal NthPortal changed the title Make LazyList.cons.apply lazier Increase laziness of LazyList.cons.apply Nov 20, 2020
@NthPortal
Copy link
Contributor Author

@SethTisue is that okay?

@SethTisue
Copy link
Member

@NthPortal better — if you want to improve it further, I would suggest adding an example code snippet that is affected by the change, and describe how it is affected. even though I've looked at this stuff multiple times before, when I see LazyList.cons.apply my reaction is still "huh? what's that?" and I have to go look it up. an example would really help, I think.

@som-snytt
Copy link
Contributor

"If you're as lazy as LazyList, you probably don't need to know more."

Sometimes it helps to be usefully vague.

Do I need to learn this?

  • No.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
library:collections PRs involving changes to the standard collection library release-notes worth highlighting in next release notes
Projects
None yet
5 participants