-
-
Save jml/c308c351d2ccf39d03a421370d7e48df 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
#!/usr/bin/env stack | |
-- stack --resolver lts-6 --install-ghc runghc --package protolude | |
{-# LANGUAGE NoImplicitPrelude #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Protolude | |
getDifferences :: (Ord a, Ord b, Eq c) => (a -> (b, c)) -> [a] -> [a] -> [(b, (c, c))] | |
getDifferences _ _ [] = [] | |
getDifferences _ [] _ = [] | |
getDifferences splitter xs@(x:xs') ys@(y:ys') = | |
let (x1, x2) = splitter x | |
(y1, y2) = splitter y | |
in | |
case compare x1 y1 of | |
LT -> getDifferences splitter xs' ys | |
GT -> getDifferences splitter xs ys' | |
EQ -> | |
let next = getDifferences splitter xs' ys' in | |
if x2 == y2 | |
then next | |
else (x1, (x2, y2)):next | |
main :: IO () | |
main = do | |
let left = [("foo", 1),("bar", 2),("baz", 3)] :: [(Text, Int)] | |
let right = [("foo", 1),("bar", 3),("baz", 3)] | |
putStrLn $ (show $ getDifferences identity left right :: Text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I understand the logic of this right, this should be the same thing using
Map
?