1
1
mirror of https://github.com/sol/hpack.git synced 2024-10-04 11:47:15 +03:00

Expose more stuff from Data.Aeson.Config.FromValue

This commit is contained in:
Simon Hengel 2018-08-08 17:48:59 +08:00
parent ef2b7db493
commit 8baee6ae37

View File

@ -28,6 +28,8 @@ module Data.Aeson.Config.FromValue (
, withNumber
, withBool
, parseArray
, (.:)
, (.:?)
@ -90,10 +92,13 @@ instance FromValue a => FromValue (Maybe a) where
fromValue value = liftParser (parseJSON value) >>= traverse fromValue
instance FromValue a => FromValue [a] where
fromValue = withArray $ zipWithM (parseIndexed fromValue) [0..] . V.toList
where
parseIndexed :: (Value -> Parser a) -> Int -> Value -> Parser a
parseIndexed p n value = p value <?> Index n
fromValue = withArray (parseArray fromValue)
parseArray :: (Value -> Parser a) -> Array -> Parser [a]
parseArray f = zipWithM (parseIndexed f) [0..] . V.toList
where
parseIndexed :: (Value -> Parser a) -> Int -> Value -> Parser a
parseIndexed p n value = p value <?> Index n
instance FromValue a => FromValue (Map String a) where
fromValue = withObject $ \ o -> do