on master help sign in
Fix a bug in uniq function. Fixes #191.
commite6699ece2f391f8cfc5e91f414bfe8ba89127829 authorPranay Sashank <pranaysashank@gmail.com> dateWed 22 May 2019, 02:01 (7 years ago) parent6ed211f
2 files changed+18−4
src/Streamly/Streams/StreamD.hs+1−1 test/Prop.hs+17−3
src/Streamly/Streams/StreamD.hs+1−1
@@ -2117,7 +2117,7 @@ uniq (Stream step state) = Stream step' (Nothing, state)
21172117 r <- step gst st
21182118 case r of
21192119 Yield y s | x == y -> return $ Skip (Just x, s)
2120− | otherwise -> return $ Yield x (Just y, s)
2120+ | otherwise -> return $ Yield y (Just y, s)
21212121 Skip s -> return $ Skip (Just x, s)
21222122 Stop -> return Stop
21232123
test/Prop.hs+17−3
@@ -578,7 +578,8 @@ transformCombineOpsOrdered constr desc eq t = do
578578 transform (dropWhile (> 0)) t (S.dropWhile (> 0))
579579 prop (desc <> " scan") $ transform (scanl' (+) 0) t (S.scanl' (+) 0)
580580
581− -- XXX add uniq
581+ prop (desc <> " uniq") $ transform referenceUniq t S.uniq
582+
582583 prop (desc <> " deleteBy (<=) 0") $
583584 transform (deleteBy (<=) 0) t (S.deleteBy (<=) 0)
584585
@@ -617,10 +618,23 @@ wrapOutOfBounds f i x | null x = Nothing
617618 | otherwise = Just (f x i)
618619
619620wrapThe :: Eq a => [a] -> Maybe a
620−wrapThe (x:xs) | all (x ==) xs = Just x
621− | otherwise = Nothing
621+wrapThe (x:xs)
622+ | all (x ==) xs = Just x
623+ | otherwise = Nothing
622624wrapThe [] = Nothing
623625
626+-- This is the reference uniq implementation to compare uniq against,
627+-- we can use uniq from vector package, but for now this should
628+-- suffice.
629+referenceUniq :: Eq a => [a] -> [a]
630+referenceUniq = go
631+ where
632+ go [] = []
633+ go (x:[]) = [x]
634+ go (x:y:xs)
635+ | x == y = go (x : xs)
636+ | otherwise = x : go (y : xs)
637+
624638eliminationOps
625639 :: ([Int] -> t IO Int)
626640 -> String