-
Notifications
You must be signed in to change notification settings - Fork 21
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
Stream#withFilter should be override. #3265
Comments
Imported From: https://issues.scala-lang.org/browse/SI-3265?orig=1 |
@dubochet said: |
Eastsun (eastsun) said: |
@paulp said:
Sure! He's right in principle, and I don't know if I'm going to run into some nutty issue in practice. Shoot, I already added a whole withFilter implementation to poor little Option. It doesn't look like any collection with nontrivial differences can avoid it without suffering consequences. Anyway, I'll take that as a hint that I should check that patch out and commit something if I can. |
Eastsun (eastsun) said:
Take Tuple2 for example, I think #2634 would be fixed if we chang the implementation of class Tuple2#Zipped like this: class Zipped[+Repr1, +El1, +Repr2, +El2](coll1: TraversableLike[El1, Repr1], coll2: IterableLike[El2, Repr2]) {
def map[B, To](f: (El1, El2) => B)(implicit cbf: CanBuildFrom[Repr1, B, To]): To = {
val elems2 = coll2.iterator
for(el1 <- coll1 if(elems2.hasNext)) yield f(el1, elems2.next)
}
...
} And Tuple2#zip should be changed in the same way. Since I don't have chance to test it, I apologize if I have missed something. |
@paulp said:
I encourage you to try it out. I'm hopeful that it's me who is missing something, because I'd like it to work. I agree that the for comprehensions should be rewritten like that now that withFilter exists, but it doesn't make any difference when it comes to termination. |
Eastsun (eastsun) said:
It confused me very much. I try to find the reason why it doesn't work as my expected. I find another Ticket #3273. |
Eastsun (eastsun) said:
I have some ideas about #2634 and I post it here: [http://old.nabble.com/Some-ideas-of-lazy-version-takeWhile-method-in-TraversableLike.-td28189940.html] |
Now the method withFilter of scala.collection.immutable.Stream is defined in scala.collection.TraversableLike. This lead to some problems:
I think we should override withFilter in Stream like following(not test):
The text was updated successfully, but these errors were encountered: