Skip to content
Snippets Groups Projects
Commit 3d3f562b authored by Agata Murawska's avatar Agata Murawska
Browse files

Remove explicit recursion from sanitizeDictResults


Since ERpcError is still not a monad, a simple foldr will have to
do for now.

Signed-off-by: default avatarAgata Murawska <agatamurawska@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 70c2362e
No related branches found
No related tags found
No related merge requests found
...@@ -224,12 +224,12 @@ executeRpcCall nodes call = ...@@ -224,12 +224,12 @@ executeRpcCall nodes call =
-- | Helper function that is used to read dictionaries of values. -- | Helper function that is used to read dictionaries of values.
sanitizeDictResults :: [(String, J.Result a)] -> ERpcError [(String, a)] sanitizeDictResults :: [(String, J.Result a)] -> ERpcError [(String, a)]
sanitizeDictResults [] = Right [] sanitizeDictResults =
sanitizeDictResults ((_, J.Error err):_) = Left $ JsonDecodeError err foldr sanitize1 (Right [])
sanitizeDictResults ((name, J.Ok val):xs) = where
case sanitizeDictResults xs of sanitize1 _ (Left e) = Left e
Left err -> Left err sanitize1 (_, J.Error e) _ = Left $ JsonDecodeError e
Right res' -> Right $ (name, val):res' sanitize1 (name, J.Ok v) (Right res) = Right $ (name, v) : res
-- | Helper function to tranform JSON Result to Either RpcError b. -- | Helper function to tranform JSON Result to Either RpcError b.
-- Note: For now we really only use it for b s.t. Rpc c b for some c -- Note: For now we really only use it for b s.t. Rpc c b for some c
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment