on master help sign in
Fix a bug in uniq function. Fixes #191.
e6699ecPranay Sashank
src/Streamly/Streams/StreamD.hs+1−1
@@ -2117,7 +2117,7 @@ uniq (Stream step state) = Stream step' (Nothing, state)
2117 r <- step gst st
2117 r <- step gst st
2118 case r of
2118 case r of
2119 Yield y s | x == y -> return $ Skip (Just x, s)
2119 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)
2121 Skip s -> return $ Skip (Just x, s)
2121 Skip s -> return $ Skip (Just x, s)
2122 Stop -> return Stop
2122 Stop -> return Stop
2123
2123
test/Prop.hs+17−3
@@ -578,7 +578,8 @@ transformCombineOpsOrdered constr desc eq t = do
578 transform (dropWhile (> 0)) t (S.dropWhile (> 0))
578 transform (dropWhile (> 0)) t (S.dropWhile (> 0))
579 prop (desc <> " scan") $ transform (scanl' (+) 0) t (S.scanl' (+) 0)
579 prop (desc <> " scan") $ transform (scanl' (+) 0) t (S.scanl' (+) 0)
580
580
581− -- XXX add uniq
581+ prop (desc <> " uniq") $ transform referenceUniq t S.uniq
582+
582 prop (desc <> " deleteBy (<=) 0") $
583 prop (desc <> " deleteBy (<=) 0") $
583 transform (deleteBy (<=) 0) t (S.deleteBy (<=) 0)
584 transform (deleteBy (<=) 0) t (S.deleteBy (<=) 0)
584
585
@@ -617,10 +618,23 @@ wrapOutOfBounds f i x | null x = Nothing
617 | otherwise = Just (f x i)
618 | otherwise = Just (f x i)
618
619
619wrapThe :: Eq a => [a] -> Maybe a
620wrapThe :: Eq a => [a] -> Maybe a
621+wrapThe (x:xs)
620−wrapThe (x:xs) | all (x ==) xs = Just x
622+ | all (x ==) xs = Just x
621− | otherwise = Nothing
623+ | otherwise = Nothing
622wrapThe [] = Nothing
624wrapThe [] = Nothing
623
625
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+
624eliminationOps
638eliminationOps
625 :: ([Int] -> t IO Int)
639 :: ([Int] -> t IO Int)
626 -> String
640 -> String