Call-by-name parameters for `NonEmptyLazyList`
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 5.5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 5
Description
Methods like #:: and prepend on NonEmptyLazyList are not call-by-name currently, which causes misuse of it to blow up eagerly. For example:
val lazyList = 1 #:: 2 #:: "c".toInt #:: LazyList(4)
println(lazyList.head) // prints "a"
// blows up here: java.lang.NumberFormatException: For input string: "c"
val nonEmptyLazyList = 1 #:: 2 #:: "c".toInt #:: NonEmptyLazyList(4)
println(nonEmptyLazyList.head)
I would understand the argument that this is misuse and it's not worth being defensive against it, but my thinking was for the sake of consistency with LazyList. Also, I think this is the same reason why methods like cats.effect.IO#as are also call-by-name.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the NonEmptyLazyList definitions and the #:: and prepend implementations, then compare their evaluation behavior with LazyList. Confirm the example defers the NumberFormatException until the value is demanded, and add coverage for the call-by-name behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100