Call-by-name parameters for `NonEmptyLazyList`
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.
I didn't know how far to take this. I see things like +: are also defined on NonEmptyLazyList directly, so those could be modified too... but plain LazyList does not have this because it relies on the one defined in SeqOps. Which feels inconsistent to me, but that's how the standard Scala collections work I guess.
I guess this is because currently NonEmptyLazyList implements NonEmptyCollection which has append and prepend methods defined as non-lazy. And since both +: and #:: simply call to prepend under the hood, there's no sense to make them lazy.
But I wonder though – was it a good idea to inherit NonEmptyLazyList from NonEmptyCollection?