on master help sign in
fix warnings, example and readme
bba7045Harendra Kumar
README.md+3−17
@@ -447,31 +447,17 @@ main = withArg2 cp
447``` haskell
447``` haskell
448wcl =
448wcl =
449 S.length
449 S.length
450− . FL.splitSuffixBy (== fromIntegral (ord '\n')) FL.drain
450+ . FL.splitBySuffix (== fromIntegral (ord '\n')) FL.drain
451 . FH.read
451 . FH.read
452main = withArg wcl >>= print
452main = withArg wcl >>= print
453```
453```
454
454
455−### grep -c
456−
457−Note that `grep -c` counts the number of lines where the pattern occurs whereas
458−the snippet below counts the total number of occurrences of the pattern,
459−therefore, the output may differ.
460−
461−``` haskell
462−grepc pat =
463− S.length
464− . FL.splitOn (A.fromList (map (fromIntegral . ord) pat)) FL.drain
465− . FH.read
466−main = withArg (grepc "pattern") >>= print . subtract 1
467−```
468−
469### Average Line Length
455### Average Line Length
470
456
471``` haskell
457``` haskell
472avgll =
458avgll =
473 FL.foldl' avg
459 FL.foldl' avg
474− . FL.splitSuffixBy (== fromIntegral (ord '\n')) FL.length
460+ . FL.splitBySuffix (== fromIntegral (ord '\n')) FL.length
475 . FH.read
461 . FH.read
476
462
477 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
463 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
@@ -486,7 +472,7 @@ main = withArg avgll >>= print
486llhisto =
472llhisto =
487 FL.foldl' (FL.classify FL.length)
473 FL.foldl' (FL.classify FL.length)
488 . S.map bucket
474 . S.map bucket
489− . FL.splitSuffixBy (== fromIntegral (ord '\n')) FL.length
475+ . FL.splitBySuffix (== fromIntegral (ord '\n')) FL.length
490 . FH.read
476 . FH.read
491
477
492 where
478 where
examples/FileSinkServer.hs+1−1
@@ -31,6 +31,6 @@ main = do
31 where
31 where
32
32
33 recv =
33 recv =
34− FL.splitSuffixBy' (== '\n') A.toArray
34+ FL.splitBySuffix (== '\n') A.toArray
35 . decodeChar8
35 . decodeChar8
36 . NS.read
36 . NS.read
src/Streamly/Fold.hs+30−30
@@ -240,7 +240,7 @@ module Streamly.Fold
240
240
241 -- By == Keeping the separator
241 -- By == Keeping the separator
242 -- , splitBy
242 -- , splitBy
243− -- , splitBySuffix
243+ , splitBySuffix
244 -- , splitByPrefix
244 -- , splitByPrefix
245 , wordsBy -- stripAndCompactBy
245 , wordsBy -- stripAndCompactBy
246
246
@@ -817,9 +817,9 @@ toList = Fold (\f x -> return $ f . (x :))
817-- @since 0.7.0
817-- @since 0.7.0
818
818
819-- xn : ... : x2 : x1 : []
819-- xn : ... : x2 : x1 : []
820−{-# INLINABLE toListRev #-}
820+{-# INLINABLE _toListRev #-}
821−toListRev :: Monad m => Fold m a [a]
821+_toListRev :: Monad m => Fold m a [a]
822−toListRev = Fold (\xs x -> return $ x:xs) (return []) return
822+_toListRev = Fold (\xs x -> return $ x:xs) (return []) return
823
823
824-- | A fold that buffers its input to a pure stream.
824-- | A fold that buffers its input to a pure stream.
825--
825--
@@ -827,9 +827,9 @@ toListRev = Fold (\xs x -> return $ x:xs) (return []) return
827-- be very inefficient, consider using "Streamly.Array" instead.
827-- be very inefficient, consider using "Streamly.Array" instead.
828--
828--
829-- @since 0.7.0
829-- @since 0.7.0
830−{-# INLINE toStream #-}
830+{-# INLINE _toStream #-}
831−toStream :: Monad m => Fold m a (SerialT Identity a)
831+_toStream :: Monad m => Fold m a (SerialT Identity a)
832−toStream = Fold (\f x -> return $ f . (x `K.cons`))
832+_toStream = Fold (\f x -> return $ f . (x `K.cons`))
833 (return id)
833 (return id)
834 (return . ($ K.nil))
834 (return . ($ K.nil))
835
835
@@ -845,9 +845,9 @@ toStream = Fold (\f x -> return $ f . (x `K.cons`))
845-- @since 0.7.0
845-- @since 0.7.0
846
846
847-- xn : ... : x2 : x1 : []
847-- xn : ... : x2 : x1 : []
848−{-# INLINABLE toStreamRev #-}
848+{-# INLINABLE _toStreamRev #-}
849−toStreamRev :: Monad m => Fold m a (SerialT Identity a)
849+_toStreamRev :: Monad m => Fold m a (SerialT Identity a)
850−toStreamRev = Fold (\xs x -> return $ x `S.cons` xs) (return S.nil) return
850+_toStreamRev = Fold (\xs x -> return $ x `S.cons` xs) (return S.nil) return
851
851
852------------------------------------------------------------------------------
852------------------------------------------------------------------------------
853-- Partial Folds
853-- Partial Folds
@@ -1044,9 +1044,9 @@ lfilter f (Fold step begin done) = Fold step' begin done
1044-- | Like 'lfilter' but with a monadic predicate.
1044-- | Like 'lfilter' but with a monadic predicate.
1045--
1045--
1046-- @since 0.7.0
1046-- @since 0.7.0
1047−{-# INLINABLE lfilterM #-}
1047+{-# INLINABLE _lfilterM #-}
1048−lfilterM :: Monad m => (a -> m Bool) -> Fold m a r -> Fold m a r
1048+_lfilterM :: Monad m => (a -> m Bool) -> Fold m a r -> Fold m a r
1049−lfilterM f (Fold step begin done) = Fold step' begin done
1049+_lfilterM f (Fold step begin done) = Fold step' begin done
1050 where
1050 where
1051 step' x a = do
1051 step' x a = do
1052 use <- f a
1052 use <- f a
@@ -1125,14 +1125,14 @@ ltakeWhile predicate (Fold step initial done) = Fold step' initial' done'
1125-- the segments instead of discarding the leftover.
1125-- the segments instead of discarding the leftover.
1126--
1126--
1127-- @since 0.7.0
1127-- @since 0.7.0
1128−{-# INLINE splitAt #-}
1128+{-# INLINE _splitAt #-}
1129−splitAt
1129+_splitAt
1130 :: Monad m
1130 :: Monad m
1131 => Int
1131 => Int
1132 -> Fold m a b
1132 -> Fold m a b
1133 -> Fold m a c
1133 -> Fold m a c
1134 -> Fold m a (b, c)
1134 -> Fold m a (b, c)
1135−splitAt n (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
1135+_splitAt n (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
1136 Fold step init extract
1136 Fold step init extract
1137 where
1137 where
1138 init = Tuple3' <$> return n <*> initialL <*> initialR
1138 init = Tuple3' <$> return n <*> initialL <*> initialR
@@ -1226,8 +1226,8 @@ sessionsOf n f xs =
1226 splitBySuffix isNothing (lcatMaybes f)
1226 splitBySuffix isNothing (lcatMaybes f)
1227 (intersperseByTime n (return Nothing) (S.map Just xs))
1227 (intersperseByTime n (return Nothing) (S.map Just xs))
1228 where
1228 where
1229− intersperseByTime n f xs = xs `Par.parallelEndByFirst` S.repeatM timed
1229+ intersperseByTime n' f' xs' = xs' `Par.parallelEndByFirst` S.repeatM timed
1230− where timed = liftIO (threadDelay (round $ n * 1000000)) >> f
1230+ where timed = liftIO (threadDelay (round $ n' * 1000000)) >> f'
1231
1231
1232------------------------------------------------------------------------------
1232------------------------------------------------------------------------------
1233-- Element Aware APIs
1233-- Element Aware APIs
@@ -1329,14 +1329,14 @@ span p (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
1329-- > ([],[3,2,1])
1329-- > ([],[3,2,1])
1330--
1330--
1331-- @since 0.7.0
1331-- @since 0.7.0
1332−{-# INLINE break #-}
1332+{-# INLINE _break #-}
1333−break
1333+_break
1334 :: Monad m
1334 :: Monad m
1335 => (a -> Bool)
1335 => (a -> Bool)
1336 -> Fold m a b
1336 -> Fold m a b
1337 -> Fold m a c
1337 -> Fold m a c
1338 -> Fold m a (b, c)
1338 -> Fold m a (b, c)
1339−break p = span (not . p)
1339+_break p = span (not . p)
1340
1340
1341-- | Like 'spanBy' but applies the predicate in a rolling fashion i.e.
1341-- | Like 'spanBy' but applies the predicate in a rolling fashion i.e.
1342-- predicate is applied to the previous and the next input elements.
1342-- predicate is applied to the previous and the next input elements.
@@ -1749,11 +1749,11 @@ splitOnAny subseq f m = undefined -- D.fromStreamD $ D.splitOnAny f subseq (D.to
1749-- > lines = splitSuffixOn "\n"
1749-- > lines = splitSuffixOn "\n"
1750--
1750--
1751-- @since 0.7.0
1751-- @since 0.7.0
1752−{-# INLINE splitOnSuffixSeq #-}
1752+{-# INLINE _splitOnSuffixSeq #-}
1753−splitOnSuffixSeq
1753+_splitOnSuffixSeq
1754 :: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
1754 :: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
1755 => Array a -> Fold m a b -> t m a -> t m b
1755 => Array a -> Fold m a b -> t m a -> t m b
1756−splitOnSuffixSeq patt f m =
1756+_splitOnSuffixSeq patt f m =
1757 D.fromStreamD $ D.splitSuffixOn False patt f (D.toStreamD m)
1757 D.fromStreamD $ D.splitSuffixOn False patt f (D.toStreamD m)
1758
1758
1759{-
1759{-
@@ -1800,11 +1800,11 @@ wordsOn subseq f m = undefined -- D.fromStreamD $ D.wordsOn f subseq (D.toStream
1800-- > ["he","ll","o"]
1800-- > ["he","ll","o"]
1801--
1801--
1802-- @since 0.7.0
1802-- @since 0.7.0
1803−{-# INLINE splitBySeq #-}
1803+{-# INLINE _splitBySeq #-}
1804−splitBySeq
1804+_splitBySeq
1805 :: (IsStream t, MonadAsync m, Storable a, Enum a, Eq a)
1805 :: (IsStream t, MonadAsync m, Storable a, Enum a, Eq a)
1806 => Array a -> Fold m a b -> t m a -> t m b
1806 => Array a -> Fold m a b -> t m a -> t m b
1807−splitBySeq patt f m = S.intersperseM (foldl' f (A.read patt)) $ splitOnSeq patt f m
1807+_splitBySeq patt f m = S.intersperseM (foldl' f (A.read patt)) $ splitOnSeq patt f m
1808
1808
1809-- | Like 'splitSuffixOn' but keeps the suffix intact in the splits.
1809-- | Like 'splitSuffixOn' but keeps the suffix intact in the splits.
1810--
1810--
@@ -1835,11 +1835,11 @@ splitBySeq patt f m = S.intersperseM (foldl' f (A.read patt)) $ splitOnSeq patt
1835-- > ["a.",".","b.","."]
1835-- > ["a.",".","b.","."]
1836--
1836--
1837-- @since 0.7.0
1837-- @since 0.7.0
1838−{-# INLINE splitBySuffixSeq #-}
1838+{-# INLINE _splitBySuffixSeq #-}
1839−splitBySuffixSeq
1839+_splitBySuffixSeq
1840 :: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
1840 :: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
1841 => Array a -> Fold m a b -> t m a -> t m b
1841 => Array a -> Fold m a b -> t m a -> t m b
1842−splitBySuffixSeq patt f m =
1842+_splitBySuffixSeq patt f m =
1843 D.fromStreamD $ D.splitSuffixOn True patt f (D.toStreamD m)
1843 D.fromStreamD $ D.splitSuffixOn True patt f (D.toStreamD m)
1844
1844
1845{-
1845{-