Skip to content

takeInterval yields nothing, dropInterval drops nothing #3271

Description

@GuillaumedeVolpiano

Package: streamly 0.11.1 (the definitions are unchanged on master as of 2026-11-20)
GHC: 9.12.4, threaded runtime

Reproduction

import qualified Streamly.Data.Stream.Prelude as Stream

main :: IO ()
main = do
  Stream.toList (Stream.takeInterval 1 (Stream.fromList [1 .. 10 :: Int])) >>= print
  Stream.toList (Stream.dropInterval 1 (Stream.fromList [1 .. 10 :: Int])) >>= print

Expected: [1,2,3,4,5,6,7,8,9,10], then [].

Actual: [], then [1,2,3,4,5,6,7,8,9,10].

Cause

In src/Streamly/Internal/Data/Stream/Time.hs:

takeInterval d =
    Stream.catMaybes
        . Stream.takeWhile isNothing
        . interject (return Nothing) d . fmap Just

dropInterval d =
    Stream.catMaybes
        . Stream.dropWhile isNothing
        . interject (return Nothing) d . fmap Just

The elements of the stream are wrapped in Just and the timer ticks are
Nothing. takeWhile isNothing therefore stops at the first element of the
stream, and dropWhile isNothing stops dropping at once. The predicates look
inverted: takeInterval should keep elements while they are Just, and
dropInterval should drop them while they are Just, then drop the tick.

Since intervalsOf and the sampleInterval* functions do not go through these
two, they are not affected (sampleIntervalEnd behaves as documented in my
tests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bug

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions