Skip to content

Instantly share code, notes, and snippets.

@cgibbard
Created July 27, 2021 21:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgibbard/b129fe412b74cca676ac2a2c941362ea to your computer and use it in GitHub Desktop.
Save cgibbard/b129fe412b74cca676ac2a2c941362ea to your computer and use it in GitHub Desktop.
data Pick a b c = PickLeft (a -> c -> c) | PickRight (b -> c -> c) | PickBoth (a -> b -> c -> c)
biwalk :: (a -> b -> Pick a b c) -> ([a] -> c) -> ([b] -> c) -> c -> [a] -> [b] -> c
biwalk b l r z = go
where
go [] [] = z
go xs [] = l xs
go [] ys = r ys
go (x:xs) (y:ys) = case b x y of
PickLeft u -> u x (go xs (y:ys))
PickRight v -> v y (go (x:xs) ys)
PickBoth w -> w x y (go xs ys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment