@@ -56,6 +56,7 @@ module Streamly.Internal.Data.Fold
56 , genericLength
56 , genericLength
57 , countDistinct
57 , countDistinct
58 , countDistinctInt
58 , countDistinctInt
60 , rollingHash
61 , rollingHash
61 , rollingHashWithSalt
62 , rollingHashWithSalt
@@ -84,6 +85,8 @@ module Streamly.Internal.Data.Fold
84 , toStream
85 , toStream
85 , toStreamRev
86 , toStreamRev
88 -- ** Terminating Folds
91 -- ** Terminating Folds
89 -- Element folds. Terminate after inspecting one element. All these can be
92 -- Element folds. Terminate after inspecting one element. All these can be
@@ -146,6 +149,7 @@ module Streamly.Internal.Data.Fold
146 , sampleFromthen
149 , sampleFromthen
147 -- , ldeleteBy
150 -- , ldeleteBy
148 -- , luniq
151 -- , luniq
150 -- ** Mapping Filters
154 -- ** Mapping Filters
151 , catMaybes
155 , catMaybes
@@ -278,9 +282,6 @@ module Streamly.Internal.Data.Fold
279 , duplicate
283 , duplicate
285 -- * Deprecated
286 -- * Deprecated
286 , sequence
287 , sequence
@@ -2274,6 +2275,15 @@ classifyMutWith f fld =
2274classify :: (Monad m, Ord k) => Fold m a b -> Fold m (k, a) (Map k b)
2275classify :: (Monad m, Ord k) => Fold m a b -> Fold m (k, a) (Map k b)
2275classify = classifyWith fst . lmap snd
2276classify = classifyWith fst . lmap snd
2278+-- | Determine the frequency of each element in the stream.
2280+-- You can just collect the keys of the resulting map to get the unique
2281+-- elements in the stream.
2283+{-# INLINE frequency #-}
2284+frequency :: (Monad m, Ord a) => Fold m a (Map a Int)
2285+frequency = classifyWith id length
2277------------------------------------------------------------------------------
2287------------------------------------------------------------------------------
2278-- Unzipping
2288-- Unzipping
2279------------------------------------------------------------------------------
2289------------------------------------------------------------------------------