@@ -50,6 +50,7 @@ module Streamly.Internal.Data.Stream.IsStream.Reduce
51 , splitOnSuffix
51 , splitOnSuffix
52 , splitOnPrefix
52 , splitOnPrefix
54 -- , splitBy
55 -- , splitBy
55 , splitWithSuffix
56 , splitWithSuffix
@@ -68,7 +69,7 @@ module Streamly.Internal.Data.Stream.IsStream.Reduce
69 -- Splitting using multiple sequence separators
70 -- Splitting using multiple sequence separators
70 -- , splitOnAnySeq
71 -- , splitOnAnySeq
71− -- , splitOnAnySuffixSeq
72+ , splitOnSuffixSeqAny
72 -- , splitOnAnyPrefixSeq
73 -- , splitOnAnyPrefixSeq
74 -- -- *** Splitting By Streams
75 -- -- *** Splitting By Streams
@@ -125,6 +126,7 @@ module Streamly.Internal.Data.Stream.IsStream.Reduce
125 -- output stream.
126 -- output stream.
127 , wordsBy -- stripAndCompactBy
128 , wordsBy -- stripAndCompactBy
129 , groupsBy
131 , groupsBy
130 , groupsByRolling
132 , groupsByRolling
@@ -203,7 +205,7 @@ import Prelude hiding (concatMap, map)
204-- Space: @O(1)@
206-- Space: @O(1)@
206−-- /Unimplemented/ - Help wanted.
208+-- /Unimplemented/
207{-# INLINE dropPrefix #-}
209{-# INLINE dropPrefix #-}
208dropPrefix ::
210dropPrefix ::
209 -- (Eq a, IsStream t, Monad m) =>
211 -- (Eq a, IsStream t, Monad m) =>
@@ -215,7 +217,7 @@ dropPrefix = error "Not implemented yet!"
216-- Space: @O(n)@ where n is the length of the infix.
218-- Space: @O(n)@ where n is the length of the infix.
218−-- /Unimplemented/ - Help wanted.
220+-- /Unimplemented/
219{-# INLINE dropInfix #-}
221{-# INLINE dropInfix #-}
220dropInfix ::
222dropInfix ::
221 -- (Eq a, IsStream t, Monad m) =>
223 -- (Eq a, IsStream t, Monad m) =>
@@ -227,7 +229,7 @@ dropInfix = error "Not implemented yet!"
228-- Space: @O(n)@ where n is the length of the suffix.
230-- Space: @O(n)@ where n is the length of the suffix.
230−-- /Unimplemented/ - Help wanted.
232+-- /Unimplemented/
231{-# INLINE dropSuffix #-}
233{-# INLINE dropSuffix #-}
232dropSuffix ::
234dropSuffix ::
233 -- (Eq a, IsStream t, Monad m) =>
235 -- (Eq a, IsStream t, Monad m) =>
@@ -382,6 +384,10 @@ parseMany
382parseMany p m =
384parseMany p m =
383 fromStreamD $ D.parseMany (PRD.fromParserK p) (toStreamD m)
385 fromStreamD $ D.parseMany (PRD.fromParserK p) (toStreamD m)
387+-- | Same as parseMany but for StreamD streams.
385{-# INLINE parseManyD #-}
391{-# INLINE parseManyD #-}
386parseManyD
392parseManyD
387 :: (IsStream t, MonadThrow m)
393 :: (IsStream t, MonadThrow m)
@@ -394,7 +400,7 @@ parseManyD p m =
394-- | Apply a stream of parsers to an input stream and emit the results in the
400-- | Apply a stream of parsers to an input stream and emit the results in the
395-- output stream.
401-- output stream.
397−-- /Pre-release/
403+-- /Unimplemented/
399{-# INLINE parseSequence #-}
405{-# INLINE parseSequence #-}
400parseSequence
406parseSequence
@@ -446,45 +452,6 @@ parseIterate
446parseIterate f i m = fromStreamD $
452parseIterate f i m = fromStreamD $
447 D.parseIterate (PRD.fromParserK . f) i (toStreamD m)
453 D.parseIterate (PRD.fromParserK . f) i (toStreamD m)
449−------------------------------------------------------------------------------
450−-- Generalized grouping
451−------------------------------------------------------------------------------
453−-- This combinator is the most general grouping combinator and can be used to
454−-- implement all other grouping combinators.
456−-- XXX check if this can implement the splitOn combinator i.e. we can slide in
457−-- new elements, slide out old elements and incrementally compute the hash.
458−-- Also, can we implement the windowed classification combinators using this?
460−-- In fact this is a parse. Instead of using a special return value in the fold
461−-- we are using a mapping function.
463−-- Note that 'scanl'' (usually followed by a map to extract the desired value
464−-- from the accumulator) can be used to realize many implementations e.g. a
465−-- sliding window implementation. A scan followed by a mapMaybe is also a good
466−-- pattern to express many problems where we want to emit a filtered output and
467−-- not emit an output on every input.
469−-- Passing on of the initial accumulator value to the next fold is equivalent
470−-- to returning the leftover concept.
473−-- | @groupScan splitter fold stream@ folds the input stream using @fold@.
474−-- @splitter@ is applied on the accumulator of the fold every time an item is
475−-- consumed by the fold. The fold continues until @splitter@ returns a 'Just'
476−-- value. A 'Just' result from the @splitter@ specifies a result to be emitted
477−-- in the output stream and the initial value of the accumulator for the next
478−-- group's fold. This allows us to control whether to start fresh for the next
479−-- fold or to continue from the previous fold's output.
481−{-# INLINE groupScan #-}
483− :: (IsStream t, Monad m)
484− => (x -> m (Maybe (b, x))) -> Fold m a x -> t m a -> t m b
485−groupScan split fold m = undefined
488------------------------------------------------------------------------------
455------------------------------------------------------------------------------
489-- Grouping
456-- Grouping
490------------------------------------------------------------------------------
457------------------------------------------------------------------------------
@@ -820,16 +787,16 @@ splitWithSuffix predicate f = foldMany (FL.takeEndBy predicate f)
820-- >>> splitList [1,2,3,3,4] [1,2,3,3,4]
787-- >>> splitList [1,2,3,3,4] [1,2,3,3,4]
821-- > [[],[]]
788-- > [[],[]]
824-- This can be implemented easily using Rabin Karp
790-- This can be implemented easily using Rabin Karp
825-- | Split on any one of the given patterns.
791-- | Split on any one of the given patterns.
826{-# INLINE splitOnAny #-}
795{-# INLINE splitOnAny #-}
828− :: (IsStream t, Monad m, Storable a, Integral a)
796+splitOnAny :: -- (IsStream t, Monad m, Storable a, Integral a) =>
829− => [Array a] -> Fold m a b -> t m a -> t m b
797+ [Array a] -> Fold m a b -> t m a -> t m b
830−splitOnAny subseq f m = undefined
798+splitOnAny _subseq _f _m =
831− -- fromStreamD $ D.splitOnAny f subseq (toStreamD m)
799+ undefined -- D.fromStreamD $ D.splitOnAny f subseq (D.toStreamD m)
834-- XXX use a non-monadic intersperse to remove the MonadAsync constraint.
801-- XXX use a non-monadic intersperse to remove the MonadAsync constraint.
835-- XXX Use two folds, one ring buffer fold for separator sequence and the other
802-- XXX Use two folds, one ring buffer fold for separator sequence and the other
@@ -925,16 +892,14 @@ splitOnSuffixSeq
925splitOnSuffixSeq patt f m =
892splitOnSuffixSeq patt f m =
926 fromStreamD $ D.splitOnSuffixSeq False patt f (toStreamD m)
893 fromStreamD $ D.splitOnSuffixSeq False patt f (toStreamD m)
929-- | Like 'splitOn' but drops any empty splits.
895-- | Like 'splitOn' but drops any empty splits.
931{-# INLINE wordsOn #-}
898{-# INLINE wordsOn #-}
933− :: (IsStream t, Monad m, Storable a, Eq a)
899+wordsOn :: -- (IsStream t, Monad m, Storable a, Eq a) =>
934− => Array a -> Fold m a b -> t m a -> t m b
900+ Array a -> Fold m a b -> t m a -> t m b
935−wordsOn subseq f m = undefined
901+wordsOn _subseq _f _m =
936− -- fromStreamD $ D.wordsOn f subseq (toStreamD m)
902+ undefined -- D.fromStreamD $ D.wordsOn f subseq (D.toStreamD m)
939-- | Like 'splitOnSuffixSeq' but keeps the suffix intact in the splits.
904-- | Like 'splitOnSuffixSeq' but keeps the suffix intact in the splits.
@@ -972,16 +937,15 @@ splitWithSuffixSeq
972splitWithSuffixSeq patt f m =
937splitWithSuffixSeq patt f m =
973 fromStreamD $ D.splitOnSuffixSeq True patt f (toStreamD m)
938 fromStreamD $ D.splitOnSuffixSeq True patt f (toStreamD m)
976-- This can be implemented easily using Rabin Karp
940-- This can be implemented easily using Rabin Karp
977-- | Split post any one of the given patterns.
941-- | Split post any one of the given patterns.
978{-# INLINE splitOnSuffixSeqAny #-}
944{-# INLINE splitOnSuffixSeqAny #-}
980− :: (IsStream t, Monad m, Storable a, Integral a)
945+splitOnSuffixSeqAny :: -- (IsStream t, Monad m, Storable a, Integral a) =>
981− => [Array a] -> Fold m a b -> t m a -> t m b
946+ [Array a] -> Fold m a b -> t m a -> t m b
982−splitOnSuffixSeqAny subseq f m = undefined
947+splitOnSuffixSeqAny _subseq _f _m = undefined
983− -- fromStreamD $ D.splitPostAny f subseq (toStreamD m)
948+ -- D.fromStreamD $ D.splitPostAny f subseq (D.toStreamD m)
986------------------------------------------------------------------------------
950------------------------------------------------------------------------------
987-- Chunking
951-- Chunking
@@ -1061,16 +1025,6 @@ chunksOfTimeout n timeout f =
1061-- Windowed classification
1025-- Windowed classification
1062------------------------------------------------------------------------------
1026------------------------------------------------------------------------------
1064−-- We divide the stream into windows or chunks in space or time and each window
1065−-- can be associated with a key, all events associated with a particular key in
1066−-- the window can be folded to a single result. The stream can be split into
1067−-- windows by size or by using a split predicate on the elements in the stream.
1068−-- For example, when we receive a closing flag, we can close the window.
1070−-- A "chunk" is a space window and a "session" is a time window. Are there any
1071−-- other better short words to describe them. An alternative is to use
1072−-- "swindow" and "twindow". Another word for "session" could be "spell".
1074-- TODO: To mark the position in space or time we can have Indexed or
1028-- TODO: To mark the position in space or time we can have Indexed or
1075-- TimeStamped types. That can make it easy to deal with the position indices
1029-- TimeStamped types. That can make it easy to deal with the position indices
1076-- or timestamps.
1030-- or timestamps.