on master help sign in
Move eqBy, cmpBy, the to StreamD.Eliminate.
9c483a0Pranay Sashank
src/Streamly/Internal/Data/Stream/StreamD/Eliminate.hs+29
@@ -65,6 +65,13 @@ module Streamly.Internal.Data.Stream.StreamD.Eliminate
65 , (!!)
65 , (!!)
66 , toSVarParallel
66 , toSVarParallel
67
67
68+ -- ** Comparisons
69+ , eqBy
70+ , cmpBy
71+
72+ -- ** Transformation comprehensions
73+ , the
74+
68 -- ** Substreams
75 -- ** Substreams
69 , isPrefixOf
76 , isPrefixOf
70 , isSubsequenceOf
77 , isSubsequenceOf
@@ -1058,6 +1065,28 @@ runStateT initial (Stream step state) = Stream step' (state, initial)
1058 Skip s -> Skip (s, return sv')
1065 Skip s -> Skip (s, return sv')
1059 Stop -> Stop
1066 Stop -> Stop
1060
1067
1068+------------------------------------------------------------------------------
1069+-- Transformation comprehensions
1070+------------------------------------------------------------------------------
1071+
1072+{-# INLINE_NORMAL the #-}
1073+the :: (Eq a, Monad m) => Stream m a -> m (Maybe a)
1074+the (Stream step state) = go state
1075+ where
1076+ go st = do
1077+ r <- step defState st
1078+ case r of
1079+ Yield x s -> go' x s
1080+ Skip s -> go s
1081+ Stop -> return Nothing
1082+ go' n st = do
1083+ r <- step defState st
1084+ case r of
1085+ Yield x s | x == n -> go' n s
1086+ | otherwise -> return Nothing
1087+ Skip s -> go' n s
1088+ Stop -> return (Just n)
1089+
1061------------------------------------------------------------------------------
1090------------------------------------------------------------------------------
1062-- Substreams
1091-- Substreams
1063------------------------------------------------------------------------------
1092------------------------------------------------------------------------------
src/Streamly/Internal/Data/Stream/StreamD/Transform.hs−29
@@ -82,17 +82,10 @@ module Streamly.Internal.Data.Stream.StreamD.Transform
82 , zipWith
82 , zipWith
83 , zipWithM
83 , zipWithM
84
84
85− -- * Comparisons
86− , eqBy
87− , cmpBy
88−
89 -- * Merging
85 -- * Merging
90 , mergeBy
86 , mergeBy
91 , mergeByM
87 , mergeByM
92
88
93− -- * Transformation comprehensions
94− , the
95−
96 -- * Concurrent Application
89 -- * Concurrent Application
97 , mkParallel
90 , mkParallel
98 , mkParallelD
91 , mkParallelD
@@ -871,28 +864,6 @@ mergeBy
871 => (a -> a -> Ordering) -> Stream m a -> Stream m a -> Stream m a
864 => (a -> a -> Ordering) -> Stream m a -> Stream m a -> Stream m a
872mergeBy cmp = mergeByM (\a b -> return $ cmp a b)
865mergeBy cmp = mergeByM (\a b -> return $ cmp a b)
873
866
874−------------------------------------------------------------------------------
875−-- Transformation comprehensions
876−------------------------------------------------------------------------------
877−
878−{-# INLINE_NORMAL the #-}
879−the :: (Eq a, Monad m) => Stream m a -> m (Maybe a)
880−the (Stream step state) = go state
881− where
882− go st = do
883− r <- step defState st
884− case r of
885− Yield x s -> go' x s
886− Skip s -> go s
887− Stop -> return Nothing
888− go' n st = do
889− r <- step defState st
890− case r of
891− Yield x s | x == n -> go' n s
892− | otherwise -> return Nothing
893− Skip s -> go' n s
894− Stop -> return (Just n)
895−
896-------------------------------------------------------------------------------
867-------------------------------------------------------------------------------
897-- Concurrent application and fold
868-- Concurrent application and fold
898-------------------------------------------------------------------------------
869-------------------------------------------------------------------------------