patternyamlMinor
Update only specific field of specific item (data) in List from YAML
Viewed 0 times
itemfieldupdateyamlspecificlistfromdataonly
Problem
I don't like the logic to update
The other definitions used there is here:
[Repository] list here because I need to map whole list to change only specific field of specific node, I especially don't like that I need to provide all other fields in changing node alike (location x) etc... Major trouble there is that if I will edit data model I will be forced to edit a lot of code where I use it like this.hashupdate :: String -> String -> IO ()
hashupdate hash rep =
withConfig $ \ymlx ->
let ymlprocess = ifSo $ do
rsdata >= ymlprocessThe other definitions used there is here:
data Repository = Repository { location :: String
, branches :: [String]
, upstream :: String
, enabled :: Maybe Bool
, clean :: Maybe Bool
, post_rebuild :: Maybe [String]
, syncGroup :: Maybe String
, hash :: Maybe String
} deriving (Show, Eq)
yEncode :: ToJSON iToJSONable => FilePath -> iToJSONable -> IO()
yEncode fnm dat = do
let bs = Data.Yaml.encode dat
BS.writeFile fnm bsSolution
I don't like that I need to provide all other fields in changing node
alike
You can "update" a field of a record like so:
I would recommend against names like
alike
(location x) etc...You can "update" a field of a record like so:
where enR x = if rep == location x then x { hash = Just hash } else xI would recommend against names like
fnm, dat, ed, enR, etc. You should also use consistent casing (postRebuild instead of post_rebuild).Code Snippets
where enR x = if rep == location x then x { hash = Just hash } else xContext
StackExchange Code Review Q#61148, answer score: 3
Revisions (0)
No revisions yet.