-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 Streaming and StreamingT dropWhile functions #856
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,15 +524,15 @@ sealed abstract class Streaming[A] extends Product with Serializable { lhs => | |
* | ||
* For example: | ||
* | ||
* Streaming(1, 2, 3, 4, 5, 6, 7).takeWhile(n => n != 4) | ||
* Streaming(1, 2, 3, 4, 5, 6, 7).dropWhile(n => n != 4) | ||
* | ||
* Will result in: Streaming(4, 5, 6, 7) | ||
*/ | ||
def dropWhile(f: A => Boolean): Streaming[A] = | ||
this match { | ||
case Empty() => Empty() | ||
case Wait(lt) => Wait(lt.map(_.dropWhile(f))) | ||
case Cons(a, lt) => if (f(a)) Empty() else Cons(a, lt.map(_.dropWhile(f))) | ||
case Cons(a, lt) => if (f(a)) Wait(lt.map(_.dropWhile(f))) else Cons(a, lt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can save an allocation by doing something like this here: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good spot - Thanks! - In general, is there any reason to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To answer your question: there are times when you get a finer-grained type from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool - that makes a lot of sense - and thanks a million for following up!!! I guess in this instance there would have been no value, as there is no additional type information required, but I can definitely imagine scenarios, where this could be valuable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, totally agree with what @non said. It didn't occur to me that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! - I actually don't have much preference - it's more natural defaults :-). I went with your suggestion anyway. |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,7 +251,7 @@ sealed abstract class StreamingT[F[_], A] extends Product with Serializable { lh | |
*/ | ||
def dropWhile(f: A => Boolean)(implicit ev: Functor[F]): StreamingT[F, A] = | ||
this match { | ||
case Cons(a, ft) => if (f(a)) Empty() else Cons(a, ft.map(_.dropWhile(f))) | ||
case Cons(a, ft) => if (f(a)) Wait(ft.map(_.dropWhile(f))) else Cons(a, ft) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
case Wait(ft) => Wait(ft.map(_.dropWhile(f))) | ||
case Empty() => Empty() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have sbt-doctest in place, we should change these to be compiler-verified!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I submitted mikejcurry#1 to your PR branch