1
1
module Data.Argonaut.Decode.Combinators
2
- ( getField
3
- , getFieldOptional
4
- , getFieldOptional '
2
+ ( parseField
3
+ , parseFieldOptional
4
+ , parseFieldOptional '
5
5
, defaultField
6
6
, (.:)
7
7
, (.:!)
@@ -21,25 +21,25 @@ import Foreign.Object as FO
21
21
-- | Attempt to get the value for a given key on an `Object Json`.
22
22
-- |
23
23
-- | 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 =
27
27
maybe
28
28
(Left $ " Expected field " <> show s)
29
29
(elaborateFailure s <<< decodeJson)
30
30
(FO .lookup s o)
31
31
32
- infix 7 getField as .:
32
+ infix 7 parseField as .:
33
33
34
34
-- | Attempt to get the value for a given key on an `Object Json`.
35
35
-- |
36
36
-- | The result will be `Right Nothing` if the key and value are not present,
37
37
-- | or if the key is present and the value is `null`.
38
38
-- |
39
39
-- | 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 =
43
43
maybe
44
44
(pure Nothing )
45
45
decode
@@ -50,7 +50,7 @@ getFieldOptional' o s =
50
50
then pure Nothing
51
51
else Just <$> decodeJson json
52
52
53
- infix 7 getFieldOptional ' as .:?
53
+ infix 7 parseFieldOptional ' as .:?
54
54
55
55
-- | Attempt to get the value for a given key on an `Object Json`.
56
56
-- |
@@ -59,17 +59,17 @@ infix 7 getFieldOptional' as .:?
59
59
-- |
60
60
-- | This function will treat `null` as a value and attempt to decode it into your desired type.
61
61
-- | 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 =
65
65
maybe
66
66
(pure Nothing )
67
67
decode
68
68
(FO .lookup s o)
69
69
where
70
70
decode json = Just <$> (elaborateFailure s <<< decodeJson) json
71
71
72
- infix 7 getFieldOptional as .:!
72
+ infix 7 parseFieldOptional as .:!
73
73
74
74
-- | Helper for use in combination with `.:?` to provide default values for optional
75
75
-- | `Object Json` fields.
0 commit comments