on master help sign in
fix warnings, example and readme
commitbba704561bc3e66b33a93b9c58b418cd56cc1b72 authorHarendra Kumar <harendra.kumar@gmail.com> dateFri 2 Aug 2019, 06:56 (7 years ago) parent00e887b
3 files changed+34−48
README.md+3−17 examples/FileSinkServer.hs+1−1 src/Streamly/Fold.hs+30−30
README.md+3−17
@@ -447,31 +447,17 @@ main = withArg2 cp
447447``` haskell
448448wcl =
449449 S.length
450− . FL.splitSuffixBy (== fromIntegral (ord '\n')) FL.drain
450+ . FL.splitBySuffix (== fromIntegral (ord '\n')) FL.drain
451451 . FH.read
452452main = withArg wcl >>= print
453453```
454454
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−
469455### Average Line Length
470456
471457``` haskell
472458avgll =
473459 FL.foldl' avg
474− . FL.splitSuffixBy (== fromIntegral (ord '\n')) FL.length
460+ . FL.splitBySuffix (== fromIntegral (ord '\n')) FL.length
475461 . FH.read
476462
477463 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
@@ -486,7 +472,7 @@ main = withArg avgll >>= print
486472llhisto =
487473 FL.foldl' (FL.classify FL.length)
488474 . S.map bucket
489− . FL.splitSuffixBy (== fromIntegral (ord '\n')) FL.length
475+ . FL.splitBySuffix (== fromIntegral (ord '\n')) FL.length
490476 . FH.read
491477
492478 where
examples/FileSinkServer.hs+1−1
@@ -31,6 +31,6 @@ main = do
3131 where
3232
3333 recv =
34− FL.splitSuffixBy' (== '\n') A.toArray
34+ FL.splitBySuffix (== '\n') A.toArray
3535 . decodeChar8
3636 . NS.read
src/Streamly/Fold.hs+30−30
@@ -240,7 +240,7 @@ module Streamly.Fold
240240
241241 -- By == Keeping the separator
242242 -- , splitBy
243− -- , splitBySuffix
243+ , splitBySuffix
244244 -- , splitByPrefix
245245 , wordsBy -- stripAndCompactBy
246246
@@ -817,9 +817,9 @@ toList = Fold (\f x -> return $ f . (x :))
817817-- @since 0.7.0
818818
819819-- xn : ... : x2 : x1 : []
820−{-# INLINABLE toListRev #-}
821−toListRev :: Monad m => Fold m a [a]
822−toListRev = Fold (\xs x -> return $ x:xs) (return []) return
820+{-# INLINABLE _toListRev #-}
821+_toListRev :: Monad m => Fold m a [a]
822+_toListRev = Fold (\xs x -> return $ x:xs) (return []) return
823823
824824-- | A fold that buffers its input to a pure stream.
825825--
@@ -827,9 +827,9 @@ toListRev = Fold (\xs x -> return $ x:xs) (return []) return
827827-- be very inefficient, consider using "Streamly.Array" instead.
828828--
829829-- @since 0.7.0
830−{-# INLINE toStream #-}
831−toStream :: Monad m => Fold m a (SerialT Identity a)
832−toStream = Fold (\f x -> return $ f . (x `K.cons`))
830+{-# INLINE _toStream #-}
831+_toStream :: Monad m => Fold m a (SerialT Identity a)
832+_toStream = Fold (\f x -> return $ f . (x `K.cons`))
833833 (return id)
834834 (return . ($ K.nil))
835835
@@ -845,9 +845,9 @@ toStream = Fold (\f x -> return $ f . (x `K.cons`))
845845-- @since 0.7.0
846846
847847-- xn : ... : x2 : x1 : []
848−{-# INLINABLE toStreamRev #-}
849−toStreamRev :: Monad m => Fold m a (SerialT Identity a)
850−toStreamRev = Fold (\xs x -> return $ x `S.cons` xs) (return S.nil) return
848+{-# INLINABLE _toStreamRev #-}
849+_toStreamRev :: Monad m => Fold m a (SerialT Identity a)
850+_toStreamRev = Fold (\xs x -> return $ x `S.cons` xs) (return S.nil) return
851851
852852------------------------------------------------------------------------------
853853-- Partial Folds
@@ -1044,9 +1044,9 @@ lfilter f (Fold step begin done) = Fold step' begin done
10441044-- | Like 'lfilter' but with a monadic predicate.
10451045--
10461046-- @since 0.7.0
1047−{-# INLINABLE lfilterM #-}
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
1047+{-# INLINABLE _lfilterM #-}
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
10501050 where
10511051 step' x a = do
10521052 use <- f a
@@ -1125,14 +1125,14 @@ ltakeWhile predicate (Fold step initial done) = Fold step' initial' done'
11251125-- the segments instead of discarding the leftover.
11261126--
11271127-- @since 0.7.0
1128−{-# INLINE splitAt #-}
1129−splitAt
1128+{-# INLINE _splitAt #-}
1129+_splitAt
11301130 :: Monad m
11311131 => Int
11321132 -> Fold m a b
11331133 -> Fold m a c
11341134 -> 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) =
11361136 Fold step init extract
11371137 where
11381138 init = Tuple3' <$> return n <*> initialL <*> initialR
@@ -1226,8 +1226,8 @@ sessionsOf n f xs =
12261226 splitBySuffix isNothing (lcatMaybes f)
12271227 (intersperseByTime n (return Nothing) (S.map Just xs))
12281228 where
1229− intersperseByTime n f xs = xs `Par.parallelEndByFirst` S.repeatM timed
1230− where timed = liftIO (threadDelay (round $ n * 1000000)) >> f
1229+ intersperseByTime n' f' xs' = xs' `Par.parallelEndByFirst` S.repeatM timed
1230+ where timed = liftIO (threadDelay (round $ n' * 1000000)) >> f'
12311231
12321232------------------------------------------------------------------------------
12331233-- Element Aware APIs
@@ -1329,14 +1329,14 @@ span p (Fold stepL initialL extractL) (Fold stepR initialR extractR) =
13291329-- > ([],[3,2,1])
13301330--
13311331-- @since 0.7.0
1332−{-# INLINE break #-}
1333−break
1332+{-# INLINE _break #-}
1333+_break
13341334 :: Monad m
13351335 => (a -> Bool)
13361336 -> Fold m a b
13371337 -> Fold m a c
13381338 -> Fold m a (b, c)
1339−break p = span (not . p)
1339+_break p = span (not . p)
13401340
13411341-- | Like 'spanBy' but applies the predicate in a rolling fashion i.e.
13421342-- 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
17491749-- > lines = splitSuffixOn "\n"
17501750--
17511751-- @since 0.7.0
1752−{-# INLINE splitOnSuffixSeq #-}
1753−splitOnSuffixSeq
1752+{-# INLINE _splitOnSuffixSeq #-}
1753+_splitOnSuffixSeq
17541754 :: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
17551755 => Array a -> Fold m a b -> t m a -> t m b
1756−splitOnSuffixSeq patt f m =
1756+_splitOnSuffixSeq patt f m =
17571757 D.fromStreamD $ D.splitSuffixOn False patt f (D.toStreamD m)
17581758
17591759{-
@@ -1800,11 +1800,11 @@ wordsOn subseq f m = undefined -- D.fromStreamD $ D.wordsOn f subseq (D.toStream
18001800-- > ["he","ll","o"]
18011801--
18021802-- @since 0.7.0
1803−{-# INLINE splitBySeq #-}
1804−splitBySeq
1803+{-# INLINE _splitBySeq #-}
1804+_splitBySeq
18051805 :: (IsStream t, MonadAsync m, Storable a, Enum a, Eq a)
18061806 => 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
18081808
18091809-- | Like 'splitSuffixOn' but keeps the suffix intact in the splits.
18101810--
@@ -1835,11 +1835,11 @@ splitBySeq patt f m = S.intersperseM (foldl' f (A.read patt)) $ splitOnSeq patt
18351835-- > ["a.",".","b.","."]
18361836--
18371837-- @since 0.7.0
1838−{-# INLINE splitBySuffixSeq #-}
1839−splitBySuffixSeq
1838+{-# INLINE _splitBySuffixSeq #-}
1839+_splitBySuffixSeq
18401840 :: (IsStream t, MonadIO m, Storable a, Enum a, Eq a)
18411841 => Array a -> Fold m a b -> t m a -> t m b
1842−splitBySuffixSeq patt f m =
1842+_splitBySuffixSeq patt f m =
18431843 D.fromStreamD $ D.splitSuffixOn True patt f (D.toStreamD m)
18441844
18451845{-