3
\$\begingroup\$

I don't like the logic to update [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 <- yDecode ymlx :: IO [Repository]
 let ed = map enR rsdata
 where enR x = if rep == (location x)
 then (Repository (location x)
 (branches x)
 (upstream x)
 (enabled x)
 (clean x)
 (post_rebuild x)
 (syncGroup x)
 (Just hash))
 else x
 yEncode ymlx ed
 in doesFileExist ymlx >>= ymlprocess

The 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 bs
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Aug 27, 2014 at 4:34
\$\endgroup\$
0

1 Answer 1

3
\$\begingroup\$

I don't like that I need to provide all other fields in changing node 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 x

I would recommend against names like fnm, dat, ed, enR, etc. You should also use consistent casing (postRebuild instead of post_rebuild).

answered Aug 27, 2014 at 4:57
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.