on master help sign in
Update docs of demux and classify
d6f9e6eHarendra Kumar
core/src/Streamly/Internal/Data/Fold.hs+10−7
@@ -201,7 +201,8 @@ module Streamly.Internal.Data.Fold
201
201
202 -- ** Demultiplexing
202 -- ** Demultiplexing
203 -- | Direct values in the input stream to different folds using an n-ary
203 -- | Direct values in the input stream to different folds using an n-ary
204− -- fold selector.
204+ -- fold selector. 'demux' is a generalization of 'classify' where each key
205+ -- of the classifier can use a different fold.
205 , demux -- XXX rename this to demux_
206 , demux -- XXX rename this to demux_
206 , demuxWith
207 , demuxWith
207 , demuxDefault -- XXX rename this to demux
208 , demuxDefault -- XXX rename this to demux
@@ -211,7 +212,9 @@ module Streamly.Internal.Data.Fold
211
212
212 -- ** Classifying
213 -- ** Classifying
213 -- | In an input stream of key value pairs fold values for different keys
214 -- | In an input stream of key value pairs fold values for different keys
214− -- in individual output buckets using the given fold.
215+ -- in individual output buckets using the given fold. 'classify' is a
216+ -- special case of 'demux' where all the branches of the demultiplexer use
217+ -- the same fold.
215 --
218 --
216 -- Different types of maps can be used with these combinators via the IsMap
219 -- Different types of maps can be used with these combinators via the IsMap
217 -- type class. Hashmap performs better when there are more collisions, trie
220 -- type class. Hashmap performs better when there are more collisions, trie
@@ -1476,7 +1479,7 @@ partition = partitionBy id
1476--
1479--
1477-- Any input that does not map to a fold in the input Map is silently ignored.
1480-- Any input that does not map to a fold in the input Map is silently ignored.
1478--
1481--
1479−-- > demuxWith f kv = fmap fst $ demuxDefaultWith f kv drain
1482+-- >>> demuxWith f kv = fmap fst $ Fold.demuxDefaultWith f kv Fold.drain
1480--
1483--
1481-- /Pre-release/
1484-- /Pre-release/
1482--
1485--
@@ -1497,7 +1500,7 @@ demuxWith f kv = fmap fst $ demuxDefaultWith f kv drain
1497-- :}
1500-- :}
1498-- fromList [("PRODUCT",8),("SUM",4)]
1501-- fromList [("PRODUCT",8),("SUM",4)]
1499--
1502--
1500−-- > demux = demuxWith id
1503+-- >>> demux = Fold.demuxWith id
1501--
1504--
1502-- /Pre-release/
1505-- /Pre-release/
1503{-# INLINE demux #-}
1506{-# INLINE demux #-}
@@ -1630,7 +1633,7 @@ demuxDefaultWith f kv (Fold dstep dinitial dextract) =
1630 return (doneMap, b)
1633 return (doneMap, b)
1631
1634
1632-- |
1635-- |
1633−-- > demuxDefault = demuxDefaultWith id
1636+-- >>> demuxDefault = Fold.demuxDefaultWith id
1634--
1637--
1635-- /Pre-release/
1638-- /Pre-release/
1636{-# INLINE demuxDefault #-}
1639{-# INLINE demuxDefault #-}
@@ -1813,12 +1816,12 @@ classifyMutWith f fld =
1813--
1816--
1814-- Same as:
1817-- Same as:
1815--
1818--
1816−-- > classify fld = Fold.classifyWith fst (lmap snd fld)
1819+-- >>> classify = Fold.classifyWith fst . Fold.lmap snd
1817--
1820--
1818-- /Pre-release/
1821-- /Pre-release/
1819{-# INLINE classify #-}
1822{-# INLINE classify #-}
1820classify :: (Monad m, Ord k) => Fold m a b -> Fold m (k, a) (Map k b)
1823classify :: (Monad m, Ord k) => Fold m a b -> Fold m (k, a) (Map k b)
1821−classify fld = classifyWith fst (lmap snd fld)
1824+classify = classifyWith fst . lmap snd
1822
1825
1823------------------------------------------------------------------------------
1826------------------------------------------------------------------------------
1824-- Unzipping
1827-- Unzipping