typelevel / typelevel/cats

Call-by-name parameters for `NonEmptyLazyList`

Open
#3,928 2 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.