queue 0.1.1.2 → 0.1.1.3
raw patch · 4 files changed
+23/−9 lines, 4 filesdep ~base
Dependency ranges changed: base
Files
- queue.cabal +2/−2
- src/Data/Queue.hs +6/−0
- src/Data/Queue/Classes.hs +5/−7
- src/Data/Queue/Instances/STM.hs +10/−0
queue.cabal view
@@ -1,5 +1,5 @@ name: queue-version: 0.1.1.2+version: 0.1.1.3 stability: provisional license: BSD3 license-file: LICENSE@@ -29,7 +29,7 @@ exposed-modules: Data.Queue Data.Queue.Classes Data.Queue.Instances- build-depends: base+ build-depends: base >= 3 extensions: CPP
src/Data/Queue.hs view
@@ -29,6 +29,12 @@ import Data.Queue.Classes import Data.Queue.Instances +-- |Construct a new FIFO of a type suitable for carrying the supplied thing.+-- Does not actually do anything with the thing supplied.+newDefaultFifoFor :: (DefaultFifo q m a, NewFifo q m) => a -> m q+newDefaultFifoFor _thing = newFifo++ -- |'RQueue' : read-only newtype wrapper for arbitrary queues newtype RQueue q = RQ q mkRQueue :: q -> RQueue q
src/Data/Queue/Classes.hs view
@@ -9,8 +9,7 @@ module Data.Queue.Classes where --- |Construct a new FIFO queue. I don't know whether or not I really want--- the 'a' parameter. It might go away sometime, so beware ;-).+-- |Construct a new FIFO queue. class Monad m => NewFifo q m where newFifo :: m q @@ -19,11 +18,6 @@ -- a more deliberate choice to be made. class Monad m => DefaultFifo q m a | q -> a, m a -> q --- |Construct a new FIFO of a type suitable for carrying the supplied thing.--- Does not actually do anything with the thing supplied.-newDefaultFifoFor :: (DefaultFifo q m a, NewFifo q m) => a -> m q-newDefaultFifoFor _thing = newFifo- class Monad m => Enqueue q m a | q -> a where -- |Put an item into a queue. May block while trying to do so. -- No constraint is placed on the behavior of the queue except that@@ -36,6 +30,10 @@ -- the queue "really ought to" come out before 'dequeue' returns -- 'Nothing'. dequeue :: q -> m (Maybe a)+ dequeueBatch :: q -> m [a]+ dequeueBatch q = do+ x <- dequeue q+ return $ case x of { Just x -> [x]; Nothing -> [] } class Monad m => DequeueWhere q m a | q -> a where -- |Pull an item matching the given predicate out of a queue.
src/Data/Queue/Instances/STM.hs view
@@ -43,6 +43,16 @@ xs <- dequeueAll ch mapM_ (enqueue ch) xs return xs+ + peekQueueTaking 0 q = return []+ peekQueueTaking (n+1) q = do+ x <- dequeue q+ case x of+ Nothing -> return []+ Just x -> do+ xs <- peekQueueTaking n q+ unGetTChan q x+ return (x:xs) instance DefaultFifo (TChan a) IO a instance NewFifo (TChan a) IO where