Created
July 10, 2015 15:42
-
-
Save Heimdell/255ea0515b09cecb0b99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (sortBy) | |
import Data.Function (on) | |
merge :: [(Int, a)] -> [(Int, b)] -> [(Maybe a, Maybe b)] | |
merge az bz = case (az, bz) of | |
((i, a) : az', (j, b) : bz') -> | |
case i `compare` j of | |
LT -> (Just a, Nothing) : merge az' bz | |
EQ -> (Just a, Just b) : merge az' bz | |
GT -> (Nothing, Just b) : merge az bz' | |
(az, []) -> [(Just a, Nothing) | (_, a) <- az] | |
([], bz) -> [(Nothing, Just b) | (_, b) <- bz] | |
outerJoin :: [(Int, a)] -> [(Int, b)] -> [(Maybe a, Maybe b)] | |
outerJoin az bz = sort az `merge` sort bz | |
where | |
sort = sortBy (compare `on` fst) | |
test = outerJoin | |
[(i, i) | i <- [0,2..100]] | |
[(i, i) | i <- [0,3..100]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment