Fix: Rename coll to iter for consistency in lazyMap examples#3139
Fix: Rename coll to iter for consistency in lazyMap examples#3139SethTisue merged 1 commit intoscala:mainfrom
coll to iter for consistency in lazyMap examples#3139Conversation
|
I'm new to scala and I found this. But I found the problem below. Maybe I need to fix document except code. Fix % scala-cli version
Scala CLI version: 1.5.1
Scala version (default): 3.5.1
Your Scala CLI version is outdated. The newest version is 1.5.4
It is recommended that you update Scala CLI through the same tool or method you used for its initial installation for avoiding the creation of outdated duplicates.scala> def lazyMap[T, U](coll: Iterable[T], f: T => U) = new Iterable[U]:
| def iterator = coll.iterator map f
|
-- [E049] Reference Error: -----------------------------------------------------
2 | def iterator = coll.iterator map f
| ^^^^
|Reference to coll is ambiguous.
|It is both defined in method lazyMap
|and inherited subsequently in anonymous class Object with Iterable[U] {...}
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: -------------------------------------------------
2 | def iterator = coll.iterator map f
| ^
| Found: (f : T => U)
| Required: U => U
|
| longer explanation available when compiling with `-explain`
2 errors found
scala> def lazyMap[T, U](iter: Iterable[T], f: T => U) = new Iterable[U]:
| def iterator = iter.iterator map f
|
def lazyMap[T, U](iter: Iterable[T], f: T => U): Iterable[U] |
iter to coll for consistency in lazyMap examplescoll to iter for consistency in lazyMap examples
|
What's wrong with I can see the desire to shorten I do see there is one existing use of For whatever it's worth, the source code consistently uses |
|
Thanks!!! The first problem is that the code uses Some try, I changed the code from I check the implementation of Iterable in trait Iterable[+A] extends IterableOnce[A]
with IterableOps[A, Iterable, Iterable[A]]
with IterableFactoryDefaults[A, Iterable] {
...
final protected def coll: this.type = this
...
}All of this leads me to think that the use of |
|
Ah, I see. Okay, let's go with |
|
Thanks a lot for checking and merging! |
https://docs.scala-lang.org/overviews/collections-2.13/views.html
fix(docs): Rename variableitertocollfor consistency with documentationReplaced variable nameiterwithcollin the code examples to align with the surrounding documentation and improve clarity.