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.
Well, the best way to do it would probably be
{-# LANGUAGE DeriveFunctor #-}
type Config = Config' String
data Config' a = Config
{ field1 :: a
, field2 :: a
, field3 :: a
} deriving (Functor)
configHeads :: Config -> Config' Char
configHeads = fmap head
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With