pipes-conduit (empty) → 0.0.1
raw patch · 4 files changed
+130/−0 lines, 4 filesdep +basedep +conduitdep +mtlsetup-changed
Dependencies added: base, conduit, mtl, pipes-core
Files
- Control/Pipe/Conduit.hs +73/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- pipes-conduit.cabal +25/−0
+ Control/Pipe/Conduit.hs view
@@ -0,0 +1,73 @@+-- | Adapters to convert conduits to pipes.+module Control.Pipe.Conduit (+ -- ** Sources+ sourcePipe,+ -- ** Conduits+ conduitPipe,+ conduitPipe_,+ -- ** Sinks+ sinkPipe,+ sinkPipe_+ ) where++import Control.Monad (void)+import Control.Monad.Trans+import Control.Monad.Trans.Resource+import Control.Pipe+import Control.Pipe.Combinators+import Control.Pipe.Exception+import Data.Conduit++-- | Convert a 'Conduit' to 'Pipe'.+--+-- The resulting pipe behaves like the original 'Conduit', and closes it upon+-- termination. Any unconsumed input is returned.+conduitPipe :: Resource m => Conduit a m b -> Pipe a b (ResourceT m) (Maybe a)+conduitPipe (Conduit push close) = do+ x <- tryAwait+ case x of+ Nothing -> lift close >>= mapM_ yield >> return Nothing+ Just input -> do+ result <- lift $ push input+ case result of+ Producing c' output -> mapM_ yield output >> conduitPipe c'+ Finished input' output -> mapM_ yield output >> return input'++-- | Convert a 'Conduit' to a 'Pipe', ignoring unconsumed input.+conduitPipe_ :: Resource m => Conduit a m b -> Pipe a b (ResourceT m) ()+conduitPipe_ = void . conduitPipe++-- | Convert a 'Source' into a 'Pipe'.+--+-- The resulting 'Pipe' is a 'Producer' which pulls from the 'Source' until+-- exhaustion and yields the received data.+sourcePipe :: Resource m => Source m a -> Pipe x a (ResourceT m) ()+sourcePipe (Source pull _) = do+ result <- lift pull+ case result of+ Open s x -> yield x >> sourcePipe s+ Closed -> return ()++-- | Convert a 'Sink' into a 'Pipe'.+--+-- Optional consumed input is returned, together with the sink result.+sinkPipe :: Resource m => Sink a m b -> Pipe a x (ResourceT m) (Maybe a, b)+sinkPipe (SinkNoData out) = return (Nothing, out)+sinkPipe (SinkLift m) = lift m >>= sinkPipe+sinkPipe (SinkData p c) = go p c+ where+ go push close = do+ mx <- tryAwait+ case mx of+ Nothing -> do+ out <- lift close+ return (Nothing, out)+ Just x -> do+ result <- lift $ push x+ case result of+ Processing push' close' -> go push' close'+ Done input output -> return (input, output)++-- | Convert a 'Sink' into a 'Pipe', ignoring results.+sinkPipe_ :: Resource m => Sink a m b -> Pipe a x (ResourceT m) ()+sinkPipe_ = void . sinkPipe
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2012, Paolo Capriotti++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Paolo Capriotti nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pipes-conduit.cabal view
@@ -0,0 +1,25 @@+Name: pipes-conduit+Version: 0.0.1+License: BSD3+License-file: LICENSE+Author: Paolo Capriotti+Maintainer: p.capriotti@gmail.com+Stability: Experimental+Homepage: https://github.com/pcapriotti/pipes-extra+Category: Control, Enumerator+Build-type: Simple+Synopsis: Conduit adapters+Description: Conduit adapters+Cabal-version: >=1.8++Source-Repository head+ Type: git+ Location: https://github.com/pcapriotti/pipes-extra++Library+ Exposed-modules: Control.Pipe.Conduit+ Build-depends:+ base (== 4.*),+ mtl,+ pipes-core (== 0.0.*),+ conduit (== 0.2.*)