-
Notifications
You must be signed in to change notification settings - Fork 11
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
groupBy changes order of characters #4
Comments
Thanks for reporting this. That's pretty bad. I'll take a PR that fixes this, or I'll do it in a few days if it hasn't already been done. |
Hi there, is this still an issue? |
I'm adding a test to check this. |
groupByCharOrder :: Assertion
groupByCharOrder = do
a <- S.toList_ . SM.mapsM Q8.toLazy $ Q8.groupBy (\a b -> succ a == b) $ Q8.fromLazy @IO "12346789"
a @?= ["1234", "6789"]
|
Or perhaps my understanding of
Still, the problem of order remains in the |
From groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
groupBy _ [] = []
groupBy eq (x:xs) = (x:ys) : groupBy eq zs
where (ys,zs) = span (eq x) xs So it's comparing every other |
Looking at the code, my guess is that this bug is actually present in |
Here we go: go (Chunk c cs)
| B.length c == 1 = Step $ to [c] (B.unsafeHead c) cs
| otherwise = Step $ to [B.unsafeTake 1 c] (B.unsafeHead c) (Chunk (B.unsafeTail c) cs)
...
to acc !w (Chunk c cs) = case findIndexOrEnd (not . rel w) c of
0 -> revNonEmptyChunks acc (Empty (go (Chunk c cs)))
n | n == B.length c -> to (B.unsafeTake n c : acc) w cs
... Notice the |
Turns out a former dev had mistaken the behaviour of |
Hi,
I noticed that groupBy appears to take the first character in each group and move it to the end.
Here's a snippet showing what happens.
{-# LANGUAGE OverloadedStrings #-}
import Data.Functor.Identity
import Data.Function
import qualified Data.ByteString.Streaming as Q
import Streaming.Internal as S
import qualified Data.ByteString.Lazy as BL
zz = S.mapsM Q.toLazy $ Q.groupBy (on (==) (== 1)) $ Q.fromLazy @Identity "1234"
-- Effect (Identity (Step ("2341" :> Return ())))
zz1 = S.mapsM Q.toLazy $ Q.groupBy (on (==) (
elem
BL.unpack "ab")) $ Q.fromLazy @Identity "1234ab5678"-- Effect (Identity (Step ("2341" :> Effect (Identity (Step ("ba" :> Effect (Identity (Step ("6785" :> Return ())))))))))
The text was updated successfully, but these errors were encountered: