-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Regulate input traffic from conduit Source with Control.FoldDebounce
--   
--   Regulate input traffic from conduit Source with Control.FoldDebounce.
--   See <a>Data.Conduit.FoldDebounce</a>
@package fold-debounce-conduit
@version 0.2.0.3


-- | Synopsis:
--   
--   <pre>
--   module Main (main) where
--   
--   import Data.Conduit (ConduitT, yield, runConduit, (.|))
--   import qualified Data.Conduit.List as CL
--   import Data.Void (Void)
--   import Control.Concurrent (threadDelay)
--   import Control.Monad.IO.Class (liftIO)
--   import Control.Monad.Trans.Resource (ResourceT, runResourceT)
--   
--   import qualified Data.Conduit.FoldDebounce as F
--   
--   fastSource :: Int -&gt; ConduitT () Int (ResourceT IO) ()
--   fastSource max_num = fastStream' 0 where
--     fastStream' count = do
--       yield count
--       if count &gt;= max_num
--         then return ()
--         else do
--           liftIO $ threadDelay 100000
--           fastStream' (count + 1)
--   
--   printSink :: Show a =&gt; ConduitT a Void (ResourceT IO) ()
--   printSink = CL.mapM_ (liftIO . putStrLn . show)
--   
--   main :: IO ()
--   main = do
--     putStrLn "-- Before debounce"
--     runResourceT $ runConduit $ fastSource 10 .| printSink
--     let debouncer = F.debounce F.Args { F.cb = undefined, -- anything will do
--                                         F.fold = (\list num -&gt; list ++ [num]),
--                                         F.init = [] }
--                                F.def { F.delay = 500000 }
--     putStrLn "-- After debounce"
--     runResourceT $ runConduit $ debouncer (fastSource 10) .| printSink
--   </pre>
--   
--   Result:
--   
--   <pre>
--   -- Before debounce
--   0
--   1
--   2
--   3
--   4
--   5
--   6
--   7
--   8
--   9
--   10
--   -- After debounce
--   [0,1,2,3,4]
--   [5,6,7,8,9]
--   [10]
--   </pre>
--   
--   This module regulates (slows down) data stream from conduit source
--   using <a>Control.FoldDebounce</a>.
--   
--   The data from the original source (type <tt>i</tt>) are pulled and
--   folded together to create an output data (type <tt>o</tt>). The output
--   data then comes out of the debounced source in a predefined interval
--   (specified by <a>delay</a> option).
--   
--   See <a>Control.FoldDebounce</a> for detail.
module Data.Conduit.FoldDebounce

-- | Debounce conduit source with <a>Control.FoldDebounce</a>. The data
--   stream from the original source (type <tt>i</tt>) is debounced and
--   folded into the data stream of the type <tt>o</tt>.
--   
--   Note that the original source is connected to a sink in another
--   thread. You may need some synchronization if the original source has
--   side-effects.
debounce :: (MonadResource m, MonadUnliftIO m) => Args i o -> Opts i o -> ConduitT () i m () -> ConduitT () o m ()

-- | Mandatory parameters for <a>new</a>.
data Args i o
Args :: (o -> IO ()) -> (o -> i -> o) -> o -> Args i o

-- | The callback to be called when the output event is emitted. Note that
--   this action is run in a different thread than the one calling
--   <a>send</a>.
--   
--   The callback should not throw any exception. In this case, the
--   <a>Trigger</a> is abnormally closed, causing
--   <a>UnexpectedClosedException</a> when <a>close</a>.
[cb] :: Args i o -> o -> IO ()

-- | The binary operation of left-fold. The left-fold is evaluated
--   strictly.
[fold] :: Args i o -> o -> i -> o

-- | The initial value of the left-fold.
[init] :: Args i o -> o

-- | Optional parameters for <a>new</a>. You can get the default by
--   <a>def</a> function.
data Opts i o

-- | The default value for this type.
def :: Default a => a

-- | The time (in microsecond) to wait after receiving an event before
--   sending it, in case more events happen in the interim.
--   
--   Default: 1 second (1000000)
delay :: Opts i o -> Int

-- | Normally, when an event is received and it's the first of a series, a
--   timer is started, and when that timer expires, all events are sent. If
--   you set this parameter to True, then the timer is reset after each
--   event is received.
--   
--   Default: False
alwaysResetTimer :: Opts i o -> Bool

-- | <a>Args</a> for stacks. Input events are accumulated in a stack, i.e.,
--   the last event is at the head of the list.
forStack :: Args i [i]

-- | <a>Args</a> for monoids. Input events are appended to the tail.
forMonoid :: Monoid i => Args i i

-- | <a>Args</a> that discards input events. The data stream from the
--   debounced source indicates the presence of data from the original
--   source.
forVoid :: Args i ()
