Copyright | (C) 2015-2016 Oleg Grenrus |
---|---|
License | BSD3 |
Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi> |
Safe Haskell | None |
Language | Haskell2010 |
Data.Aeson.Extra.CollapsedList
Description
Synopsis
- newtype CollapsedList f a = CollapsedList (f a)
- getCollapsedList :: CollapsedList f a -> f a
- parseCollapsedList :: (FromJSON a, FromJSON1 f, Alternative f) => Object -> Text -> Parser (f a)
Documentation
newtype CollapsedList f a Source #
Collapsed list, singleton is represented as the value itself in JSON encoding.
λ > decode "null" :: Maybe (CollapsedList [Int] Int) Just (CollapsedList []) λ > decode "42" :: Maybe (CollapsedList [Int] Int) Just (CollapsedList [42]) λ > decode "[1, 2, 3]" :: Maybe (CollapsedList [Int] Int) Just (CollapsedList [1,2,3])
λ > encode (CollapsedList ([] :: [Int])) "null" λ > encode (CollapsedList ([42] :: [Int])) "42" λ > encode (CollapsedList ([1, 2, 3] :: [Int])) "[1,2,3]"
Documentation rely on f
Alternative
instance behaving like lists'.
Constructors
CollapsedList (f a) |
Instances
Functor f => Functor (CollapsedList f) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods fmap :: (a -> b) -> CollapsedList f a -> CollapsedList f b # (<$) :: a -> CollapsedList f b -> CollapsedList f a # | |
Foldable f => Foldable (CollapsedList f) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods fold :: Monoid m => CollapsedList f m -> m foldMap :: Monoid m => (a -> m) -> CollapsedList f a -> m foldMap' :: Monoid m => (a -> m) -> CollapsedList f a -> m foldr :: (a -> b -> b) -> b -> CollapsedList f a -> b foldr' :: (a -> b -> b) -> b -> CollapsedList f a -> b foldl :: (b -> a -> b) -> b -> CollapsedList f a -> b foldl' :: (b -> a -> b) -> b -> CollapsedList f a -> b foldr1 :: (a -> a -> a) -> CollapsedList f a -> a foldl1 :: (a -> a -> a) -> CollapsedList f a -> a toList :: CollapsedList f a -> [a] null :: CollapsedList f a -> Bool length :: CollapsedList f a -> Int elem :: Eq a => a -> CollapsedList f a -> Bool maximum :: Ord a => CollapsedList f a -> a minimum :: Ord a => CollapsedList f a -> a sum :: Num a => CollapsedList f a -> a product :: Num a => CollapsedList f a -> a | |
Traversable f => Traversable (CollapsedList f) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods traverse :: Applicative f0 => (a -> f0 b) -> CollapsedList f a -> f0 (CollapsedList f b) sequenceA :: Applicative f0 => CollapsedList f (f0 a) -> f0 (CollapsedList f a) mapM :: Monad m => (a -> m b) -> CollapsedList f a -> m (CollapsedList f b) # sequence :: Monad m => CollapsedList f (m a) -> m (CollapsedList f a) # | |
(FromJSON1 f, Alternative f) => FromJSON1 (CollapsedList f) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (CollapsedList f a) liftParseJSONList :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [CollapsedList f a] | |
(ToJSON1 f, Foldable f) => ToJSON1 (CollapsedList f) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> CollapsedList f a -> Value liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [CollapsedList f a] -> Value liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> CollapsedList f a -> Encoding liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [CollapsedList f a] -> Encoding | |
Eq (f a) => Eq (CollapsedList f a) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods (==) :: CollapsedList f a -> CollapsedList f a -> Bool (/=) :: CollapsedList f a -> CollapsedList f a -> Bool | |
Ord (f a) => Ord (CollapsedList f a) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods compare :: CollapsedList f a -> CollapsedList f a -> Ordering (<) :: CollapsedList f a -> CollapsedList f a -> Bool (<=) :: CollapsedList f a -> CollapsedList f a -> Bool (>) :: CollapsedList f a -> CollapsedList f a -> Bool (>=) :: CollapsedList f a -> CollapsedList f a -> Bool max :: CollapsedList f a -> CollapsedList f a -> CollapsedList f a min :: CollapsedList f a -> CollapsedList f a -> CollapsedList f a | |
Read (f a) => Read (CollapsedList f a) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods readsPrec :: Int -> ReadS (CollapsedList f a) readList :: ReadS [CollapsedList f a] readPrec :: ReadPrec (CollapsedList f a) readListPrec :: ReadPrec [CollapsedList f a] | |
Show (f a) => Show (CollapsedList f a) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods showsPrec :: Int -> CollapsedList f a -> ShowS show :: CollapsedList f a -> String showList :: [CollapsedList f a] -> ShowS | |
(FromJSON1 f, Alternative f, FromJSON a) => FromJSON (CollapsedList f a) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods parseJSON :: Value -> Parser (CollapsedList f a) parseJSONList :: Value -> Parser [CollapsedList f a] | |
(ToJSON1 f, Foldable f, ToJSON a) => ToJSON (CollapsedList f a) Source # | |
Defined in Data.Aeson.Extra.CollapsedList Methods toJSON :: CollapsedList f a -> Value toEncoding :: CollapsedList f a -> Encoding toJSONList :: [CollapsedList f a] -> Value toEncodingList :: [CollapsedList f a] -> Encoding |
getCollapsedList :: CollapsedList f a -> f a Source #
parseCollapsedList :: (FromJSON a, FromJSON1 f, Alternative f) => Object -> Text -> Parser (f a) Source #
Parses possibly collapsed array value from the object's field.
λ > newtype V = V [Int] deriving (Show) λ > instance FromJSON V where parseJSON = withObject "V" $ \obj -> V <$> parseCollapsedList obj "value" λ > decode "{}" :: Maybe V Just (V []) λ > decode "{\"value\": null}" :: Maybe V Just (V []) λ > decode "{\"value\": 42}" :: Maybe V Just (V [42]) λ > decode "{\"value\": [1, 2, 3, 4]}" :: Maybe V Just (V [1,2,3,4])