Description
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.
README.md
pipes-ordered-zip
A function to tie together two sorted Haskell Iterators (Producers from the pipes library).
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] -- assumed to be ordered
b = each [ 2,3,4,5, 8] -- assumed 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)
and
import Pipes (runEffect, (>->), each)
import qualified Pipes.Prelude as P
import Pipes.OrderedZip (orderedZipAll)
main = do
let a = each ([1, 3,4, 6, 8] :: [Int])
b = each ([ 2,3,4,5, 8] :: [Int])
c = each ([ 2,3, 5, 7,8] :: [Int])
mergedProd = orderedZipAll compare [a, b, c]
_ <- runEffect $ mergedProd >-> P.print
return ()
prints
[Just 1,Nothing,Nothing]
[Nothing,Just 2,Just 2]
[Just 3,Just 3,Just 3]
[Just 4,Just 4,Nothing]
[Nothing,Just 5,Just 5]
[Just 6,Nothing,Nothing]
[Nothing,Nothing,Just 7]
[Just 8,Just 8,Just 8]