Commit 77cab679 authored by Agata Murawska's avatar Agata Murawska
Browse files

Json helper for node query



This is a helper function that gets the JSON encoding of the first
element of the list (if possible).
Signed-off-by: default avatarAgata Murawska <agatamurawska@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent d71fbcc5
......@@ -31,6 +31,7 @@ module Ganeti.JSON
, fromObjWithDefault
, fromKeyValue
, fromJVal
, jsonHead
, asJSObject
, asObjectList
, tryFromObj
......@@ -125,6 +126,11 @@ fromJVal v =
"', error: " ++ s)
J.Ok x -> return x
-- | Helper function that returns Null or first element of the list.
jsonHead :: (J.JSON b) => [a] -> (a -> b) -> J.JSValue
jsonHead [] _ = J.JSNull
jsonHead (x:_) f = J.showJSON $ f x
-- | Converts a JSON value into a JSON object.
asJSObject :: (Monad m) => J.JSValue -> m (J.JSObject J.JSValue)
asJSObject (J.JSObject a) = return a
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment