user2878641
user2878641

Reputation:

Working with tuples in Haskell

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

Answers (1)

Dietrich Epp
Dietrich Epp

Reputation: 213228

lookupAll :: Eq a => a -> [(a, b)] -> [b]
lookupAll x pairs = [b | (a, b) <- pairs, a == x]

Upvotes: 6

Related Questions