I have to write a function that given a list of keys finds all values associated with these keys in a given association list, where a key can have more then one associated values. Therefore the function has to concatenate the results of the lookups for the individual keys.
Here is my code for lookupOne:
lookupOne :: Int -> [(Int,a)] -> [a]
lookupOne x list = [values | (key,values)<-list, x==key]
Now I have to write the code for lookupAll that will look up for each key of the list and match it to the pair then append the results. I have to follow this:
lookupAll :: [Int] -> [(Int,a)] -> [a]
lookupAll ... =
So I tried many ways to do this but I just cannot figure this out: How does one extract one element of the keys (because my lookupOne only takes an Int and not [Int]) each time and look it up to the pairs of (key,value). I tried with a map function but it won't work because I don't know how to map a function that uses two arguments (lookupOne) as map apparently just takes one list as its argument. I also can't figure out how to pattern match it because apparently xs doesn't mean that on the next round it will again only extract one element of [keys] Can you please help me comprehend this <3