pipes-ordered-zip (empty) → 1.0.0.1
raw patch · 7 files changed
+166/−0 lines, 7 filesdep +basedep +foldldep +pipessetup-changed
Dependencies added: base, foldl, pipes, pipes-ordered-zip
Files
- Changelog.md +4/−0
- LICENSE +30/−0
- README.md +26/−0
- Setup.hs +2/−0
- pipes-ordered-zip.cabal +37/−0
- src-tests/testMain.hs +26/−0
- src/Pipes/OrderedZip.hs +41/−0
+ Changelog.md view
@@ -0,0 +1,4 @@+* Version 1.0.0.0:+ Initial commit with example, tests and haddock++* Version 1.0.0.1: Added a note that input sequences have to be sorted.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Stephan Schiffels (c) 2019++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 Author name here 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.
+ README.md view
@@ -0,0 +1,26 @@+# pipes-ordered-zip++A function to tie together two sorted Haskell Iterators (Producers from the [pipes library](http://hackage.haskell.org/package/pipes)).++Example:++ import Pipes (runEffect, (>->), each)+ import qualified Pipes.Prelude as P+ import Pipes.OrderedZip (orderedZip)++ main = do+ let a = each [1,3,4,6,8] -- has to be ordered+ b = each [2,3,4,5,8] -- has to be ordered+ let mergedProd = orderedZip compare a b+ _ <- runEffect $ mergedProd >-> P.print+ return ()++prints:++ (Just 1,Nothing)+ (Nothing,Just 2)+ (Just 3,Just 3)+ (Just 4,Just 4)+ (Nothing,Just 5)+ (Just 6,Nothing)+ (Just 8,Just 8)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pipes-ordered-zip.cabal view
@@ -0,0 +1,37 @@+cabal-version: >=1.10+name: pipes-ordered-zip+version: 1.0.0.1+license: BSD3+license-file: LICENSE+copyright: 2019 Stephan Schiffels+maintainer: stephan_schiffels@mac.com+author: Stephan Schiffels+homepage: https://github.com/githubuser/pipes-ordered-zip#readme+synopsis: merge two ordered Producers into a new Producer+description:+ provides a simple function to merge two Pipes-Producers into a new Producer that yields pairs of values of the original producers, but using Maybes to indicate values that are only present in the first, second or both producers. Useful to perform Left-Joins, Right-Joins and Inner-Joins on the fly using Haskell Pipes.+category: Bioinformatics+build-type: Simple+extra-source-files:+ README.md+ Changelog.md++library+ exposed-modules:+ Pipes.OrderedZip+ hs-source-dirs: src+ default-language: Haskell2010+ build-depends:+ base >=4.7 && <5,+ pipes >=4.3.9 && <4.4++test-suite pipes-ordered-zip-tests+ type: exitcode-stdio-1.0+ main-is: testMain.hs+ hs-source-dirs: src-tests+ default-language: Haskell2010+ build-depends:+ base >=4.12.0.0 && <4.13,+ pipes-ordered-zip -any,+ pipes >=4.3.9 && <4.4,+ foldl >=1.4.5 && <1.5
+ src-tests/testMain.hs view
@@ -0,0 +1,26 @@+import System.Exit (exitFailure)++import Control.Foldl (list, purely)+import Control.Monad (when)+import Pipes (each, Producer)+import Pipes.Prelude (fold')++import Pipes.OrderedZip (orderedZip)++main = do+ let a = each aVec+ b = each bVec+ let mergedProd = orderedZip compare a b+ (mergedList, _) <- purely fold' list mergedProd+ when (mergedList /= result) exitFailure+ where+ aVec = [1,3,4,6,8]+ bVec = [2,3,4,5,8]+ result = [(Just 1, Nothing),+ (Nothing, Just 2),+ (Just 3, Just 3),+ (Just 4, Just 4),+ (Nothing, Just 5),+ (Just 6, Nothing),+ (Just 8, Just 8)]+
+ src/Pipes/OrderedZip.hs view
@@ -0,0 +1,41 @@+-- |A function to tie together two sorted Haskell Iterators+module Pipes.OrderedZip (orderedZip) where++import Pipes (Producer, next, yield, lift)++-- |orderedZip takes a comparison function and two producers and merges them +-- together, creating a new Producer that yields pairs or Maybes of the two +-- datatables provided by the two original producers+orderedZip :: (Monad m) => (a -> b -> Ordering) -- ^The function to compare types of a with b+ -> Producer a m r1 -- ^The first producer (has to be ordered)+ -> Producer b m r2 -- ^The second producer (has to be ordered)+ -> Producer (Maybe a, Maybe b) m (r1, r2) -- ^The merged producer+orderedZip ord p1 p2 = do+ p1Front <- lift $ next p1+ p2Front <- lift $ next p2+ go ord p1Front p1 p2Front p2+ where+ go ord' p1Front p1' p2Front p2' = case (p1Front, p2Front) of+ (Left p1r, Left p2r) -> return (p1r, p2r)+ (Left _, Right (p2a, p2Rest)) -> do+ yield (Nothing, Just p2a)+ p2Front' <- lift $ next p2Rest+ go ord' p1Front p1' p2Front' p2Rest+ (Right (p1a, p1Rest), Left _) -> do+ yield (Just p1a, Nothing)+ p1Front' <- lift $ next p1Rest+ go ord' p1Front' p1Rest p2Front p2'+ (Right (p1a, p1Rest), Right (p2a, p2Rest)) -> case ord p1a p2a of+ LT -> do+ yield (Just p1a, Nothing)+ p1Front' <- lift $ next p1Rest+ go ord' p1Front' p1Rest p2Front p2'+ EQ -> do+ yield (Just p1a, Just p2a)+ p1Front' <- lift $ next p1Rest+ p2Front' <- lift $ next p2Rest+ go ord' p1Front' p1Rest p2Front' p2Rest+ GT -> do+ yield (Nothing, Just p2a)+ p2Front' <- lift $ next p2Rest+ go ord' p1Front p1' p2Front' p2Rest