Reputation:
So i have a list of tuples like this one xs = [("a","b"),("a","c"),("b","d")], and i want to make a function that receives this list of numbers and an element 'a', and returns what it's in the second positions of the tuples, where that 'a' is the first element. In the example above, if the function received the list xs and the letter 'a' it should return: ["b","c"]
Upvotes: 3
Views: 525
Reputation: 213228
lookupAll :: Eq a => a -> [(a, b)] -> [b]
lookupAll x pairs = [b | (a, b) <- pairs, a == x]
Upvotes: 6