-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix: Rename coll
to iter
for consistency in lazyMap examples
#3139
base: main
Are you sure you want to change the base?
Conversation
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 |
https://docs.scala-lang.org/overviews/collections-2.13/views.html
fix(docs): Rename variableiter
tocoll
for consistency with documentationReplaced variable nameiter
withcoll
in the code examples to align with the surrounding documentation and improve clarity.