how do I convert a list of custom type to a list of String

Viewed 140

I have a custom data given below:

data Item = Item {
    name:: String,
    identifier:: String,
    itemAction:: Action
    }

I want to convert a list of this data type [Item] into another list that has only the Item's name [Item.name]which is [String]

1 Answers

In case this question does not get closed, for future readers, this is a typical case for the "fmap" function, which is part of functor class, and historically referred to as "map".

fmap :: Functor f => (a -> b) -> f a -> f b

Intuitively, what fmap does is that is apply a function inside a container. This container can be a List, and in this case fmap definition will build the list composed by applying function to each element.

Related