Skip to content
Browse files

Get rid of the (.:/) combinator.

  • Loading branch information...
1 parent 6765ee8 commit 359881b2af8ff59e42a33f32f6b06a3eae4ac551 @bos committed
Showing with 5 additions and 23 deletions.
  1. +0 −1 Data/Aeson.hs
  2. +0 −1 Data/Aeson/Types.hs
  3. +5 −21 Data/Aeson/Types/Class.hs
View
1 Data/Aeson.hs
@@ -32,7 +32,6 @@ module Data.Aeson
, (.:)
, (.:?)
, (.!=)
- , (.:/)
, object
-- * Parsing
, json
View
1 Data/Aeson/Types.hs
@@ -36,7 +36,6 @@ module Data.Aeson.Types
, (.:)
, (.:?)
, (.!=)
- , (.:/)
, object
) where
View
26 Data/Aeson/Types/Class.hs
@@ -34,7 +34,6 @@ module Data.Aeson.Types.Class
, (.:)
, (.:?)
, (.!=)
- , (.:/)
, (.=)
, typeMismatch
) where
@@ -749,37 +748,22 @@ obj .:? key = case H.lookup key obj of
-- | Helper for use in combination with '.:?' to provide default
-- values for optional JSON object fields.
+--
+-- This combinator is most useful if the key and value can be absent
+-- from an object without affecting its validity and we know a default
+-- value to assign in that case. If the key and value are mandatory,
+-- use '(.:)' instead.
--
-- Example usage:
--
-- @ v1 <- o '.:?' \"opt_field_with_dfl\" .!= \"default_val\"
-- v2 <- o '.:' \"mandatory_field\"
-- v3 <- o '.:?' \"opt_field2\"
---
--- \-- alternative version of v1 using the '.:/' operator
--- v1' <- o '.:/' (\"opt_field_with_dfl\", \"default_val\")
-- @
(.!=) :: Parser (Maybe a) -> a -> Parser a
pmval .!= val = fromMaybe val <$> pmval
{-# INLINE (.!=) #-}
--- | Retrieve the value associated with the given key of an 'Object'.
--- The result is a default value if the key is not present, or 'empty'
--- if the value cannot be converted to the desired type.
---
--- This accessor is most useful if the key and value can be absent
--- from an object without affecting its validity and we know a
--- default value to assign in that case. If the key and value
--- are mandatory, use '(.:)' instead.
---
--- See also '.!=' for an alternative way to represent optional fields
--- with defaulting.
-(.:/) :: (FromJSON a) => Object -> (Text, a) -> Parser a
-obj .:/ (key, val) = case H.lookup key obj of
- Nothing -> pure val
- Just v -> parseJSON v
-{-# INLINE (.:/) #-}
-
-- | Fail parsing due to a type mismatch, with a descriptive message.
typeMismatch :: String -- ^ The name of the type you are trying to parse.
-> Value -- ^ The actual value encountered.

0 comments on commit 359881b

Please sign in to comment.
Something went wrong with that request. Please try again.