Commits

Aleksey Khudyakov committed ac84078

Add contructor for stateful builders

Comments (0)

Files changed (1)

Data/Histogram/Fill.hs

   , mkFoldBuilderG
     -- ** Pure fold
   , mkFolder
+    -- ** Generic constructors
+  , mkStatefulBuilder
     -- * Fill histograms
   , fillBuilder
   , fillBuilderVec
 {-# INLINE mkFolder #-}
 
 
+-- | Create stateful histogram builder. Output function should be safe
+--   to call multiple times and builder could be modified afterwards.
+--   So functions like @unsafeFreeze@ from @vector@ couldn't be used.
+mkStatefulBuilder :: PrimMonad m
+                  => (a -> m ()) -- ^ Add value to accumulator
+                  -> m b         -- ^ Extract result from accumulator
+                  -> HBuilderM m a b
+{-# INLINE mkStatefulBuilder #-}
+mkStatefulBuilder = HBuilderM
+
+
 
 ----------------------------------------------------------------
 -- Actual filling of histograms