Created
June 20, 2014 07:43
-
-
Save blouerat/3d97e87be4889e19147a to your computer and use it in GitHub Desktop.
1HaskellADay: keepEqual
This file contains hidden or 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
{-| Keep equal elements that are at the same position in both lists | |
Examples: | |
>>> keepEqual "hello" "world" | |
"l" | |
>>> keepEqual (repeat 1) [0..10] | |
[1] | |
>>> keepEqual [True, False, True] (repeat True) | |
[True,True] | |
-} | |
keepEqual :: Eq a => [a] -> [a] -> [a] | |
keepEqual a b = map fst $ (filter $ uncurry (==)) $ zip a b | |
-- With more curry, just like Freddy. | |
keepEqual' :: Eq a => [a] -> [a] -> [a] | |
keepEqual' = curry $ map fst . (filter $ uncurry (==)) . uncurry zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment