I have following datatype defined as record
data Config = Config
{ field1 :: String
, field2 :: String
, field3 :: String
}
I want to iterate over each field of Config
, apply some function String -> String
, for example tail
and get in return new Config
.
What is idiomatic way to do this? Preferably, without heavy 3rd party libraries.
head
function returns aChar
. Am I correct to understand that you want the type of your fields to change depending on what the supplied function returns? – Tapholetail
which will return same typeString
. I've updated questions – Fushihtail
, @leftroundabout's answer is the one to use. Note that even though you are looking for a function Config -> Config, you'll want to add a type variable to the definition of Config (as in @leftroundabout's answer) so thatfmap
can do the work for you. – Krongoldyaml
field - "data", "data:data" and "data:data:data". Since, I don't want to write parser, I'm usingdecodeFile
one-liner. It's easier for me to read through config to datatype and then provide case logic for fields afterwards – Fushih