Last active
January 15, 2019 19:16
-
-
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.
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
--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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my blog post.