Repository navigation
Fix inverted predicates in takeInterval and dropInterval #3272
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -62,7 +62,7 @@ import Control.Monad.IO.Class (MonadIO(..)) | |
| import Data.Heap (Entry(..)) | ||
| import Data.Kind (Type) | ||
| import Data.Map (Map) | ||
| import Data.Maybe (isNothing) | ||
| import Data.Maybe (isJust, isNothing) | ||
| import Data.Proxy (Proxy(..)) | ||
| import Streamly.Data.Fold (Fold) | ||
| import Streamly.Data.Array (Unbox) | ||
|
|
@@ -190,7 +190,7 @@ interject f n xs = parListEagerFst [xs, periodic f n] | |
| takeInterval :: MonadAsync m => Double -> Stream m a -> Stream m a | ||
| takeInterval d = | ||
| Stream.catMaybes | ||
| . Stream.takeWhile isNothing | ||
| . Stream.takeWhile isJust | ||
| . interject (return Nothing) d . fmap Just | ||
|
|
||
| -- | Take time interval @i@ seconds at the end of the stream. | ||
|
|
@@ -214,7 +214,7 @@ takeLastInterval = undefined | |
| dropInterval :: MonadAsync m => Double -> Stream m a -> Stream m a | ||
| dropInterval d = | ||
| Stream.catMaybes | ||
| . Stream.dropWhile isNothing | ||
| . Stream.dropWhile isJust | ||
| . interject (return Nothing) d . fmap Just | ||
|
Member
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.
In fact we do not even need to merge concurrent streams here, we can just check the time using If you are inclined to do this in this PR, I would accept the PR as is too, it fixes the bug.
Contributor
Author
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 for the suggestion! I've opened #3274 builds on this one and addresses both your comments. |
||
|
|
||
| -- | Drop time interval @i@ seconds at the end of the stream. | ||
|
|
||
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.
The current fix is good to go, but this combinator can be improved.
Instead of using
interjectwe can do something similar totimeoutfromSystem.Timeout. We can fork a thread and use a one-shot threadDelay writing to an IORef and reading the IORef synchronously from the main stream.