Revision 77cab679 htools/Ganeti/JSON.hs

b/htools/Ganeti/JSON.hs
31 31
  , fromObjWithDefault
32 32
  , fromKeyValue
33 33
  , fromJVal
34
  , jsonHead
34 35
  , asJSObject
35 36
  , asObjectList
36 37
  , tryFromObj
......
125 126
                       "', error: " ++ s)
126 127
    J.Ok x -> return x
127 128

  
129
-- | Helper function that returns Null or first element of the list.
130
jsonHead :: (J.JSON b) => [a] -> (a -> b) -> J.JSValue
131
jsonHead [] _ = J.JSNull
132
jsonHead (x:_) f = J.showJSON $ f x
133

  
128 134
-- | Converts a JSON value into a JSON object.
129 135
asJSObject :: (Monad m) => J.JSValue -> m (J.JSObject J.JSValue)
130 136
asJSObject (J.JSObject a) = return a

Also available in: Unified diff