11module Data.Argonaut.Decode.Combinators
2- ( getField
3- , getFieldOptional
4- , getFieldOptional '
2+ ( parseField
3+ , parseFieldOptional
4+ , parseFieldOptional '
55 , defaultField
66 , (.:)
77 , (.:!)
@@ -21,25 +21,25 @@ import Foreign.Object as FO
2121-- | Attempt to get the value for a given key on an `Object Json`.
2222-- |
2323-- | Use this accessor if the key and value *must* be present in your object.
24- -- | If the key and value are optional, use `getFieldOptional '` (`.:?`) instead.
25- getField :: forall a . DecodeJson a => FO.Object Json -> String -> Either String a
26- getField o s =
24+ -- | If the key and value are optional, use `parseFieldOptional '` (`.:?`) instead.
25+ parseField :: forall a . DecodeJson a => FO.Object Json -> String -> Either String a
26+ parseField o s =
2727 maybe
2828 (Left $ " Expected field " <> show s)
2929 (elaborateFailure s <<< decodeJson)
3030 (FO .lookup s o)
3131
32- infix 7 getField as .:
32+ infix 7 parseField as .:
3333
3434-- | Attempt to get the value for a given key on an `Object Json`.
3535-- |
3636-- | The result will be `Right Nothing` if the key and value are not present,
3737-- | or if the key is present and the value is `null`.
3838-- |
3939-- | Use this accessor if the key and value are optional in your object.
40- -- | If the key and value are mandatory, use `getField ` (`.:`) instead.
41- getFieldOptional ' :: forall a . DecodeJson a => FO.Object Json -> String -> Either String (Maybe a )
42- getFieldOptional ' o s =
40+ -- | If the key and value are mandatory, use `parseField ` (`.:`) instead.
41+ parseFieldOptional ' :: forall a . DecodeJson a => FO.Object Json -> String -> Either String (Maybe a )
42+ parseFieldOptional ' o s =
4343 maybe
4444 (pure Nothing )
4545 decode
@@ -50,7 +50,7 @@ getFieldOptional' o s =
5050 then pure Nothing
5151 else Just <$> decodeJson json
5252
53- infix 7 getFieldOptional ' as .:?
53+ infix 7 parseFieldOptional ' as .:?
5454
5555-- | Attempt to get the value for a given key on an `Object Json`.
5656-- |
@@ -59,17 +59,17 @@ infix 7 getFieldOptional' as .:?
5959-- |
6060-- | This function will treat `null` as a value and attempt to decode it into your desired type.
6161-- | If you would like to treat `null` values the same as absent values, use
62- -- | `getFieldOptional ` (`.:?`) instead.
63- getFieldOptional :: forall a . DecodeJson a => FO.Object Json -> String -> Either String (Maybe a )
64- getFieldOptional o s =
62+ -- | `parseFieldOptional ` (`.:?`) instead.
63+ parseFieldOptional :: forall a . DecodeJson a => FO.Object Json -> String -> Either String (Maybe a )
64+ parseFieldOptional o s =
6565 maybe
6666 (pure Nothing )
6767 decode
6868 (FO .lookup s o)
6969 where
7070 decode json = Just <$> (elaborateFailure s <<< decodeJson) json
7171
72- infix 7 getFieldOptional as .:!
72+ infix 7 parseFieldOptional as .:!
7373
7474-- | Helper for use in combination with `.:?` to provide default values for optional
7575-- | `Object Json` fields.
0 commit comments