snoyberg / mono-traversable

Type classes for mapping, folding, and traversing monomorphic containers
152 stars 63 forks source link

[conduit-combinators] Add warnings about some consumers #160

Closed neongreen closed 6 years ago

neongreen commented 6 years ago

I spent half an hour yesterday trying to understand why a dropWhileC in a pipeline doesn't work, so here are some warnings so that others won't make the same mistake.

 -- | Ignore a certain number of values in the stream.
 --
+-- Note: since this function doesn't produce anything, you probably want to
+-- use it with ('>>') instead of directly plugging it into a pipeline:
+--
+-- >>> runConduit $ yieldMany [1..5] .| drop 2 .| sinkList
+-- []
+-- >>> runConduit $ yieldMany [1..5] .| (drop 2 >> sinkList)
+-- [3,4,5]
+--
 -- Since 1.0.0
 drop :: Monad m
      => Int
      -> Consumer a m ()
INLINE_RULE(drop, n, CL.drop n)
snoyberg commented 6 years ago

Looks like the issue brought up in this blog post: https://www.snoyman.com/blog/2017/05/worst-function-in-conduit. Definitely good to have it explained in the docs like this, thanks! One issue: the code in question is shortly going to be moved over to the conduit package instead as part of the 1.3.0 release. Could you instead send this PR against the conduit repo, e.g. the https://github.com/snoyberg/conduit/blob/master/conduit/src/Data/Conduit/Combinators.hs file?

neongreen commented 6 years ago

Done: https://github.com/snoyberg/conduit/pull/348