Skip to content

Instantly share code, notes, and snippets.

@thealmarty
Last active January 15, 2019 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thealmarty/3c61053cf7649002e07ae272de71a95c to your computer and use it in GitHub Desktop.
Save thealmarty/3c61053cf7649002e07ae272de71a95c to your computer and use it in GitHub Desktop.
A zip function in Haskell that stops zipping when any of the input lists' first element is zero, or when any of the input list is empty.
--As modified from the Prelude:
zip_no_zero ::(Num a, Eq a, Num b, Eq b)=> [a] -> [b] -> [(a,b)]
zip_no_zero [] _bs = []
zip_no_zero _as [] = []
--Add to p: when any of the input lists' first element is zero.
zip_no_zero (0:as) _bs = []
zip_no_zero _as (0:bs) = []
zip_no_zero (a:as) (b:bs) = (a,b) : zip_no_zero as bs
main = do
print (zip_no_zero [0,1,2] [1,2,3])
print (zip_no_zero [1,2,3,4,0,5,6] [1,2,3,4,5,6,0])
@thealmarty
Copy link
Author

See my blog post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment