Apply two functions to a list of tuples

I have a list of tuples containing information in the following form as so:

carDatabase :: [Car]
carDatabase = [("Ford", "Focus", 2003, [("Autotrader", 9995), ("Parkers", 9495), ("Motors", 9995)]), ("Vauxhall", "Corsa", 2005, [("Autotrader", 5995), ("FOW", 7000), ("Gumtree", 6500)]), ...]

And what I am trying to do is map this list to return a list of strings with the first element of each tuple (I have a function that does this with carMan (x,_,_,_) = x) but also using the toLower function and I cannot work out a way to combine them, be it with function compositions or mapping a map etc.

This is the closest I've got.

mapTest :: [Car] -> [String]
mapTest cs = map toLower (map carMan cs)

Any help would be appreciated.

This is the error I get with:

mapTest :: [Car] -> [String]
mapTest cs = map (toLower . carMan) cs

Couldn't match type ‘Char’ with ‘[Char]’
    Expected type: Char -> String
      Actual type: Char -> Char
    In the first argument of ‘(.)’, namely ‘toLower’
    In the first argument of ‘map’, namely ‘(toLower . carMan)’

cars.hs:197:37:
    Couldn't match type ‘[Char]’ with ‘Char’
    Expected type: [(Char, String, Int, [(String, Int)])]
      Actual type: [Car]
    In the second argument of ‘map’, namely ‘cs’
    In the expression: map (toLower . carMan) cs

Answers


You can do this with function composition using .

map ((map toLower) . carMan) cs

Or make it a helper function:

strLower :: String -> String
strLower = map toLower

mapTest :: [Car] -> [String]
mapTest = map (strLower . carMan)

Need Your Help

Remove empty rows from a csv file created in Excel

r excel csv dataframe

I have a dataframe imported from an excel csv. This works so far, however the csv saves always 49'999 rows, even though there are only roughly 10'000 rows of data. The rest of the rows is all empty...

How to move lightroom catalog to a new drive

macos adobe lightroom

I use adobe lightroom for all my photos and I am constantly running into space issues. I have been told not to move my lightroom files by several individuals. Why is that? Surely there must be a...