| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Stratosphere.ResourceImports
Synopsis
- mempty :: Monoid a => a
- data Text
- data Map k a
- mkLiftParseJSON2 :: Options -> Name -> Q Exp
- mkLiftParseJSON :: Options -> Name -> Q Exp
- mkParseJSON :: Options -> Name -> Q Exp
- deriveFromJSON2 :: Options -> Name -> Q [Dec]
- deriveFromJSON1 :: Options -> Name -> Q [Dec]
- deriveFromJSON :: Options -> Name -> Q [Dec]
- mkLiftToEncoding2 :: Options -> Name -> Q Exp
- mkLiftToEncoding :: Options -> Name -> Q Exp
- mkToEncoding :: Options -> Name -> Q Exp
- mkLiftToJSON2 :: Options -> Name -> Q Exp
- mkLiftToJSON :: Options -> Name -> Q Exp
- mkToJSON :: Options -> Name -> Q Exp
- deriveToJSON2 :: Options -> Name -> Q [Dec]
- deriveToJSON1 :: Options -> Name -> Q [Dec]
- deriveToJSON :: Options -> Name -> Q [Dec]
- deriveJSON2 :: Options -> Name -> Q [Dec]
- deriveJSON1 :: Options -> Name -> Q [Dec]
- deriveJSON :: Options -> Name -> Q [Dec]
- eitherDecodeFileStrict' :: FromJSON a => FilePath -> IO (Either String a)
- eitherDecodeStrict' :: FromJSON a => ByteString -> Either String a
- eitherDecode' :: FromJSON a => ByteString -> Either String a
- eitherDecodeFileStrict :: FromJSON a => FilePath -> IO (Either String a)
- eitherDecodeStrict :: FromJSON a => ByteString -> Either String a
- eitherDecode :: FromJSON a => ByteString -> Either String a
- decodeFileStrict' :: FromJSON a => FilePath -> IO (Maybe a)
- decodeStrict' :: FromJSON a => ByteString -> Maybe a
- decode' :: FromJSON a => ByteString -> Maybe a
- decodeFileStrict :: FromJSON a => FilePath -> IO (Maybe a)
- decodeStrict :: FromJSON a => ByteString -> Maybe a
- decode :: FromJSON a => ByteString -> Maybe a
- encodeFile :: ToJSON a => FilePath -> a -> IO ()
- encode :: ToJSON a => a -> ByteString
- foldable :: (Foldable t, ToJSON a) => t a -> Encoding
- type GToJSON = GToJSON Value
- type GToEncoding = GToJSON Encoding
- toEncoding2 :: (ToJSON2 f, ToJSON a, ToJSON b) => f a b -> Encoding
- toJSON2 :: (ToJSON2 f, ToJSON a, ToJSON b) => f a b -> Value
- toEncoding1 :: (ToJSON1 f, ToJSON a) => f a -> Encoding
- toJSON1 :: (ToJSON1 f, ToJSON a) => f a -> Value
- genericLiftToEncoding :: (Generic1 f, GToJSON Encoding One (Rep1 f)) => Options -> (a -> Encoding) -> ([a] -> Encoding) -> f a -> Encoding
- genericToEncoding :: (Generic a, GToJSON Encoding Zero (Rep a)) => Options -> a -> Encoding
- genericLiftToJSON :: (Generic1 f, GToJSON Value One (Rep1 f)) => Options -> (a -> Value) -> ([a] -> Value) -> f a -> Value
- genericToJSON :: (Generic a, GToJSON Value Zero (Rep a)) => Options -> a -> Value
- data ToArgs res arity a where
- class ToJSON a where
- class KeyValue kv where
- class ToJSONKey a where
- data ToJSONKeyFunction a
- = ToJSONKeyText !(a -> Text) !(a -> Encoding' Text)
- | ToJSONKeyValue !(a -> Value) !(a -> Encoding)
- class ToJSON1 (f :: * -> *) where
- class ToJSON2 (f :: * -> * -> *) where
- pairs :: Series -> Encoding
- fromEncoding :: Encoding' tag -> Builder
- type Encoding = Encoding' Value
- data Series
- (.!=) :: Parser (Maybe a) -> a -> Parser a
- (.:!) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- (.:?) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- (.:) :: FromJSON a => Object -> Text -> Parser a
- fromJSON :: FromJSON a => Value -> Result a
- withEmbeddedJSON :: String -> (Value -> Parser a) -> Value -> Parser a
- withBool :: String -> (Bool -> Parser a) -> Value -> Parser a
- withScientific :: String -> (Scientific -> Parser a) -> Value -> Parser a
- withArray :: String -> (Array -> Parser a) -> Value -> Parser a
- withText :: String -> (Text -> Parser a) -> Value -> Parser a
- withObject :: String -> (Object -> Parser a) -> Value -> Parser a
- parseJSON2 :: (FromJSON2 f, FromJSON a, FromJSON b) => Value -> Parser (f a b)
- parseJSON1 :: (FromJSON1 f, FromJSON a) => Value -> Parser (f a)
- genericLiftParseJSON :: (Generic1 f, GFromJSON One (Rep1 f)) => Options -> (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (f a)
- genericParseJSON :: (Generic a, GFromJSON Zero (Rep a)) => Options -> Value -> Parser a
- class GFromJSON arity (f :: * -> *) where
- data FromArgs arity a where
- class FromJSON a where
- class FromJSONKey a where
- data FromJSONKeyFunction a
- = FromJSONKeyCoerce !(CoerceText a)
- | FromJSONKeyText !(Text -> a)
- | FromJSONKeyTextParser !(Text -> Parser a)
- | FromJSONKeyValue !(Value -> Parser a)
- class FromJSON1 (f :: * -> *) where
- class FromJSON2 (f :: * -> * -> *) where
- json' :: Parser Value
- json :: Parser Value
- camelTo2 :: Char -> String -> String
- defaultTaggedObject :: SumEncoding
- defaultOptions :: Options
- object :: [Pair] -> Value
- data Result a
- type Object = HashMap Text Value
- type Array = Vector Value
- data Value
- newtype DotNetTime = DotNetTime {}
- data Options
- data SumEncoding
- data Zero
- data One
- catMaybes :: [Maybe a] -> [a]
- fromDistinctDescList :: [(k, a)] -> Map k a
- fromDistinctAscList :: [(k, a)] -> Map k a
- fromDescListWithKey :: Eq k => (k -> a -> a -> a) -> [(k, a)] -> Map k a
- fromAscListWithKey :: Eq k => (k -> a -> a -> a) -> [(k, a)] -> Map k a
- fromDescListWith :: Eq k => (a -> a -> a) -> [(k, a)] -> Map k a
- fromAscListWith :: Eq k => (a -> a -> a) -> [(k, a)] -> Map k a
- fromDescList :: Eq k => [(k, a)] -> Map k a
- fromAscList :: Eq k => [(k, a)] -> Map k a
- fromListWithKey :: Ord k => (k -> a -> a -> a) -> [(k, a)] -> Map k a
- fromListWith :: Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
- fromList :: Ord k => [(k, a)] -> Map k a
- fromSet :: (k -> a) -> Set k -> Map k a
- mapKeysWith :: Ord k2 => (a -> a -> a) -> (k1 -> k2) -> Map k1 a -> Map k2 a
- mapAccumRWithKey :: (a -> k -> b -> (a, c)) -> a -> Map k b -> (a, Map k c)
- mapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> Map k b -> (a, Map k c)
- mapAccum :: (a -> b -> (a, c)) -> a -> Map k b -> (a, Map k c)
- traverseWithKey :: Applicative t => (k -> a -> t b) -> Map k a -> t (Map k b)
- mapWithKey :: (k -> a -> b) -> Map k a -> Map k b
- map :: (a -> b) -> Map k a -> Map k b
- mapEitherWithKey :: (k -> a -> Either b c) -> Map k a -> (Map k b, Map k c)
- mapEither :: (a -> Either b c) -> Map k a -> (Map k b, Map k c)
- traverseMaybeWithKey :: Applicative f => (k -> a -> f (Maybe b)) -> Map k a -> f (Map k b)
- mapMaybeWithKey :: (k -> a -> Maybe b) -> Map k a -> Map k b
- mapMaybe :: (a -> Maybe b) -> Map k a -> Map k b
- mergeWithKey :: Ord k => (k -> a -> b -> Maybe c) -> (Map k a -> Map k c) -> (Map k b -> Map k c) -> Map k a -> Map k b -> Map k c
- intersectionWithKey :: Ord k => (k -> a -> b -> c) -> Map k a -> Map k b -> Map k c
- intersectionWith :: Ord k => (a -> b -> c) -> Map k a -> Map k b -> Map k c
- differenceWithKey :: Ord k => (k -> a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a
- differenceWith :: Ord k => (a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a
- unionWithKey :: Ord k => (k -> a -> a -> a) -> Map k a -> Map k a -> Map k a
- unionWith :: Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
- unionsWith :: Ord k => (a -> a -> a) -> [Map k a] -> Map k a
- updateMaxWithKey :: (k -> a -> Maybe a) -> Map k a -> Map k a
- updateMinWithKey :: (k -> a -> Maybe a) -> Map k a -> Map k a
- updateMax :: (a -> Maybe a) -> Map k a -> Map k a
- updateMin :: (a -> Maybe a) -> Map k a -> Map k a
- updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a
- alterF :: (Functor f, Ord k) => (Maybe a -> f (Maybe a)) -> k -> Map k a -> f (Map k a)
- alter :: Ord k => (Maybe a -> Maybe a) -> k -> Map k a -> Map k a
- updateLookupWithKey :: Ord k => (k -> a -> Maybe a) -> k -> Map k a -> (Maybe a, Map k a)
- updateWithKey :: Ord k => (k -> a -> Maybe a) -> k -> Map k a -> Map k a
- update :: Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a
- adjustWithKey :: Ord k => (k -> a -> a) -> k -> Map k a -> Map k a
- adjust :: Ord k => (a -> a) -> k -> Map k a -> Map k a
- insertLookupWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> (Maybe a, Map k a)
- insertWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a
- insertWith :: Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
- insert :: Ord k => k -> a -> Map k a -> Map k a
- singleton :: k -> a -> Map k a
- findWithDefault :: Ord k => a -> k -> Map k a -> a
- showTreeWith :: (k -> a -> String) -> Bool -> Bool -> Map k a -> String
- showTree :: (Show k, Show a) => Map k a -> String
- valid :: Ord k => Map k a -> Bool
- splitRoot :: Map k b -> [Map k b]
- deleteFindMax :: Map k a -> ((k, a), Map k a)
- deleteFindMin :: Map k a -> ((k, a), Map k a)
- splitLookup :: Ord k => k -> Map k a -> (Map k a, Maybe a, Map k a)
- split :: Ord k => k -> Map k a -> (Map k a, Map k a)
- toDescList :: Map k a -> [(k, a)]
- toAscList :: Map k a -> [(k, a)]
- toList :: Map k a -> [(k, a)]
- keysSet :: Map k a -> Set k
- assocs :: Map k a -> [(k, a)]
- keys :: Map k a -> [k]
- elems :: Map k a -> [a]
- foldMapWithKey :: Monoid m => (k -> a -> m) -> Map k a -> m
- foldlWithKey' :: (a -> k -> b -> a) -> a -> Map k b -> a
- foldlWithKey :: (a -> k -> b -> a) -> a -> Map k b -> a
- foldrWithKey' :: (k -> a -> b -> b) -> b -> Map k a -> b
- foldrWithKey :: (k -> a -> b -> b) -> b -> Map k a -> b
- foldl' :: (a -> b -> a) -> a -> Map k b -> a
- foldl :: (a -> b -> a) -> a -> Map k b -> a
- foldr' :: (a -> b -> b) -> b -> Map k a -> b
- foldr :: (a -> b -> b) -> b -> Map k a -> b
- mapKeysMonotonic :: (k1 -> k2) -> Map k1 a -> Map k2 a
- mapKeys :: Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a
- partitionWithKey :: (k -> a -> Bool) -> Map k a -> (Map k a, Map k a)
- partition :: (a -> Bool) -> Map k a -> (Map k a, Map k a)
- spanAntitone :: (k -> Bool) -> Map k a -> (Map k a, Map k a)
- dropWhileAntitone :: (k -> Bool) -> Map k a -> Map k a
- takeWhileAntitone :: (k -> Bool) -> Map k a -> Map k a
- filterWithKey :: (k -> a -> Bool) -> Map k a -> Map k a
- filter :: (a -> Bool) -> Map k a -> Map k a
- isProperSubmapOfBy :: Ord k => (a -> b -> Bool) -> Map k a -> Map k b -> Bool
- isProperSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> Bool
- isSubmapOfBy :: Ord k => (a -> b -> Bool) -> Map k a -> Map k b -> Bool
- isSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> Bool
- restrictKeys :: Ord k => Map k a -> Set k -> Map k a
- intersection :: Ord k => Map k a -> Map k b -> Map k a
- withoutKeys :: Ord k => Map k a -> Set k -> Map k a
- difference :: Ord k => Map k a -> Map k b -> Map k a
- union :: Ord k => Map k a -> Map k a -> Map k a
- unions :: Ord k => [Map k a] -> Map k a
- maxView :: Map k a -> Maybe (a, Map k a)
- minView :: Map k a -> Maybe (a, Map k a)
- maxViewWithKey :: Map k a -> Maybe ((k, a), Map k a)
- minViewWithKey :: Map k a -> Maybe ((k, a), Map k a)
- deleteMax :: Map k a -> Map k a
- deleteMin :: Map k a -> Map k a
- findMax :: Map k a -> (k, a)
- lookupMax :: Map k a -> Maybe (k, a)
- findMin :: Map k a -> (k, a)
- lookupMin :: Map k a -> Maybe (k, a)
- deleteAt :: Int -> Map k a -> Map k a
- splitAt :: Int -> Map k a -> (Map k a, Map k a)
- drop :: Int -> Map k a -> Map k a
- take :: Int -> Map k a -> Map k a
- elemAt :: Int -> Map k a -> (k, a)
- lookupIndex :: Ord k => k -> Map k a -> Maybe Int
- findIndex :: Ord k => k -> Map k a -> Int
- delete :: Ord k => k -> Map k a -> Map k a
- empty :: Map k a
- lookupGE :: Ord k => k -> Map k v -> Maybe (k, v)
- lookupLE :: Ord k => k -> Map k v -> Maybe (k, v)
- lookupGT :: Ord k => k -> Map k v -> Maybe (k, v)
- lookupLT :: Ord k => k -> Map k v -> Maybe (k, v)
- notMember :: Ord k => k -> Map k a -> Bool
- member :: Ord k => k -> Map k a -> Bool
- lookup :: Ord k => k -> Map k a -> Maybe a
- size :: Map k a -> Int
- null :: Map k a -> Bool
- (\\) :: Ord k => Map k a -> Map k b -> Map k a
- (!?) :: Ord k => Map k a -> k -> Maybe a
- (!) :: Ord k => Map k a -> k -> a
- lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
- type Lens' s a = Lens s s a a
- newtype Double' = Double' {}
- class ToRef a b where
- newtype Bool' = Bool' {}
- newtype Integer' = Integer' {}
- data ValList a
- data Val a
- = Literal a
- | Ref Text
- | If Text (Val a) (Val a)
- | And (Val Bool) (Val Bool)
- | Equals (Val a) (Val a)
- | Or (Val Bool) (Val Bool)
- | GetAtt Text Text
- | Base64 (Val Text)
- | Join Text (ValList Text)
- | Select Integer (ValList a)
- | FindInMap (Val a) (Val a) (Val a)
- | ImportValue Text
- | Sub Text (Maybe (HashMap Text (Val Text)))
- sub :: Text -> Val Text
Documentation
A space efficient, packed, unboxed Unicode text type.
Instances
| Hashable Text | |
Defined in Data.Hashable.Class | |
| ToJSON Text | |
Defined in Data.Aeson.Types.ToJSON | |
| KeyValue Pair | |
| ToJSONKey Text | |
Defined in Data.Aeson.Types.ToJSON | |
| FromJSON Text | |
| FromJSONKey Text | |
Defined in Data.Aeson.Types.FromJSON | |
| Chunk Text | |
Defined in Data.Attoparsec.Internal.Types | |
| Ixed Text | |
Defined in Control.Lens.At | |
| AsEmpty Text | |
Defined in Control.Lens.Empty | |
| Reversing Text | |
Defined in Control.Lens.Internal.Iso | |
| Strict Text Text | |
| (a ~ Char, b ~ Char) => Each Text Text a b |
|
| Cons Text Text Char Char | |
| Snoc Text Text Char Char | |
| FromPairs Value (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
| v ~ Value => KeyValuePair v (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
| type State Text | |
Defined in Data.Attoparsec.Internal.Types | |
| type ChunkElem Text | |
Defined in Data.Attoparsec.Internal.Types | |
| type Item Text | |
| type Index Text | |
Defined in Control.Lens.At | |
| type IxValue Text | |
Defined in Control.Lens.At | |
A Map from keys k to values a.
Instances
| Eq2 Map | Since: containers-0.5.9 |
| Ord2 Map | Since: containers-0.5.9 |
Defined in Data.Map.Internal | |
| Show2 Map | Since: containers-0.5.9 |
| FunctorWithIndex k (Map k) | |
| FoldableWithIndex k (Map k) | |
Defined in Control.Lens.Indexed Methods ifoldMap :: Monoid m => (k -> a -> m) -> Map k a -> m # ifolded :: (Indexable k p, Contravariant f, Applicative f) => p a (f a) -> Map k a -> f (Map k a) # ifoldr :: (k -> a -> b -> b) -> b -> Map k a -> b # ifoldl :: (k -> b -> a -> b) -> b -> Map k a -> b # | |
| TraversableWithIndex k (Map k) | |
Defined in Control.Lens.Indexed Methods itraverse :: Applicative f => (k -> a -> f b) -> Map k a -> f (Map k b) # itraversed :: (Indexable k p, Applicative f) => p a (f b) -> Map k a -> f (Map k b) # | |
| Ord k => TraverseMin k (Map k) | |
Defined in Control.Lens.Traversal Methods traverseMin :: (Indexable k p, Applicative f) => p v (f v) -> Map k v -> f (Map k v) # | |
| Ord k => TraverseMax k (Map k) | |
Defined in Control.Lens.Traversal Methods traverseMax :: (Indexable k p, Applicative f) => p v (f v) -> Map k v -> f (Map k v) # | |
| Functor (Map k) | |
| Foldable (Map k) | |
Defined in Data.Map.Internal Methods fold :: Monoid m => Map k m -> m # foldMap :: Monoid m => (a -> m) -> Map k a -> m # foldr :: (a -> b -> b) -> b -> Map k a -> b # foldr' :: (a -> b -> b) -> b -> Map k a -> b # foldl :: (b -> a -> b) -> b -> Map k a -> b # foldl' :: (b -> a -> b) -> b -> Map k a -> b # foldr1 :: (a -> a -> a) -> Map k a -> a # foldl1 :: (a -> a -> a) -> Map k a -> a # elem :: Eq a => a -> Map k a -> Bool # maximum :: Ord a => Map k a -> a # minimum :: Ord a => Map k a -> a # | |
| Traversable (Map k) | |
| ToJSONKey k => ToJSON1 (Map k) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Map k a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Map k a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Map k a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Map k a] -> Encoding # | |
| (FromJSONKey k, Ord k) => FromJSON1 (Map k) | |
| Eq k => Eq1 (Map k) | Since: containers-0.5.9 |
| Ord k => Ord1 (Map k) | Since: containers-0.5.9 |
Defined in Data.Map.Internal | |
| (Ord k, Read k) => Read1 (Map k) | Since: containers-0.5.9 |
Defined in Data.Map.Internal | |
| Show k => Show1 (Map k) | Since: containers-0.5.9 |
| Ord k => IsList (Map k v) | Since: containers-0.5.6.2 |
| (Eq k, Eq a) => Eq (Map k a) | |
| (Data k, Data a, Ord k) => Data (Map k a) | |
Defined in Data.Map.Internal Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Map k a -> c (Map k a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Map k a) # toConstr :: Map k a -> Constr # dataTypeOf :: Map k a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Map k a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Map k a)) # gmapT :: (forall b. Data b => b -> b) -> Map k a -> Map k a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Map k a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Map k a -> r # gmapQ :: (forall d. Data d => d -> u) -> Map k a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Map k a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Map k a -> m (Map k a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Map k a -> m (Map k a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Map k a -> m (Map k a) # | |
| (Ord k, Ord v) => Ord (Map k v) | |
| (Ord k, Read k, Read e) => Read (Map k e) | |
| (Show k, Show a) => Show (Map k a) | |
| Ord k => Semigroup (Map k v) | |
| Ord k => Monoid (Map k v) | |
| (ToJSON v, ToJSONKey k) => ToJSON (Map k v) | |
Defined in Data.Aeson.Types.ToJSON | |
| (FromJSONKey k, Ord k, FromJSON v) => FromJSON (Map k v) | |
| (NFData k, NFData a) => NFData (Map k a) | |
Defined in Data.Map.Internal | |
| Ord k => Ixed (Map k a) | |
Defined in Control.Lens.At | |
| Ord k => At (Map k a) | |
| Ord k => Wrapped (Map k a) | |
| AsEmpty (Map k a) | |
Defined in Control.Lens.Empty | |
| (t ~ Map k' a', Ord k) => Rewrapped (Map k a) t | Use |
Defined in Control.Lens.Wrapped | |
| c ~ d => Each (Map c a) (Map d b) a b |
|
| type Item (Map k v) | |
Defined in Data.Map.Internal | |
| type Index (Map k a) | |
Defined in Control.Lens.At | |
| type IxValue (Map k a) | |
Defined in Control.Lens.At | |
| type Unwrapped (Map k a) | |
Defined in Control.Lens.Wrapped | |
Generates a lambda expression which parses the JSON encoding of the given data type or data family instance constructor by using the given parsing functions on occurrences of the last two type parameters.
Generates a lambda expression which parses the JSON encoding of the given data type or data family instance constructor by using the given parsing function on occurrences of the last type parameter.
Generates a lambda expression which parses the JSON encoding of the given data type or data family instance constructor.
Arguments
| :: Options | Encoding options. |
| -> Name | Name of the type for which to generate a |
| -> Q [Dec] |
Generates a FromJSON2 instance declaration for the given data type or
data family instance constructor.
Arguments
| :: Options | Encoding options. |
| -> Name | Name of the type for which to generate a |
| -> Q [Dec] |
Generates a FromJSON1 instance declaration for the given data type or
data family instance constructor.
Arguments
| :: Options | Encoding options. |
| -> Name | Name of the type for which to generate a |
| -> Q [Dec] |
Generates a FromJSON instance declaration for the given data type or
data family instance constructor.
Generates a lambda expression which encodes the given data type or data family instance constructor as a JSON string by using the given encoding functions on occurrences of the last two type parameters.
Generates a lambda expression which encodes the given data type or data family instance constructor as a JSON string by using the given encoding function on occurrences of the last type parameter.
Generates a lambda expression which encodes the given data type or data family instance constructor as a JSON string.
Generates a lambda expression which encodes the given data type or
data family instance constructor as a Value by using the given encoding
functions on occurrences of the last two type parameters.
Generates a lambda expression which encodes the given data type or
data family instance constructor as a Value by using the given encoding
function on occurrences of the last type parameter.
Generates a lambda expression which encodes the given data type or
data family instance constructor as a Value.
Arguments
| :: Options | Encoding options. |
| -> Name | Name of the type for which to generate a |
| -> Q [Dec] |
Generates a ToJSON2 instance declaration for the given data type or
data family instance constructor.
Arguments
| :: Options | Encoding options. |
| -> Name | Name of the type for which to generate a |
| -> Q [Dec] |
Generates a ToJSON1 instance declaration for the given data type or
data family instance constructor.
Arguments
| :: Options | Encoding options. |
| -> Name | Name of the type for which to generate a |
| -> Q [Dec] |
Generates a ToJSON instance declaration for the given data type or
data family instance constructor.
Arguments
| :: Options | Encoding options. |
| -> Name | Name of the type for which to generate |
| -> Q [Dec] |
Generates both ToJSON2 and FromJSON2 instance declarations for the given
data type or data family instance constructor.
This is a convienience function which is equivalent to calling both
deriveToJSON2 and deriveFromJSON2.
Arguments
| :: Options | Encoding options. |
| -> Name | Name of the type for which to generate |
| -> Q [Dec] |
Generates both ToJSON1 and FromJSON1 instance declarations for the given
data type or data family instance constructor.
This is a convienience function which is equivalent to calling both
deriveToJSON1 and deriveFromJSON1.
Arguments
| :: Options | Encoding options. |
| -> Name | Name of the type for which to generate |
| -> Q [Dec] |
Generates both ToJSON and FromJSON instance declarations for the given
data type or data family instance constructor.
This is a convienience function which is equivalent to calling both
deriveToJSON and deriveFromJSON.
eitherDecodeFileStrict' :: FromJSON a => FilePath -> IO (Either String a) #
Like decodeFileStrict' but returns an error message when decoding fails.
eitherDecodeStrict' :: FromJSON a => ByteString -> Either String a #
Like decodeStrict' but returns an error message when decoding fails.
eitherDecode' :: FromJSON a => ByteString -> Either String a #
Like decode' but returns an error message when decoding fails.
eitherDecodeFileStrict :: FromJSON a => FilePath -> IO (Either String a) #
Like decodeFileStrict but returns an error message when decoding fails.
eitherDecodeStrict :: FromJSON a => ByteString -> Either String a #
Like decodeStrict but returns an error message when decoding fails.
eitherDecode :: FromJSON a => ByteString -> Either String a #
Like decode but returns an error message when decoding fails.
decodeFileStrict' :: FromJSON a => FilePath -> IO (Maybe a) #
Efficiently deserialize a JSON value from a file.
If this fails due to incomplete or invalid input, Nothing is
returned.
The input file's content must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses and performs conversion immediately. See
json' for details.
decodeStrict' :: FromJSON a => ByteString -> Maybe a #
Efficiently deserialize a JSON value from a strict ByteString.
If this fails due to incomplete or invalid input, Nothing is
returned.
The input must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses and performs conversion immediately. See
json' for details.
decode' :: FromJSON a => ByteString -> Maybe a #
Efficiently deserialize a JSON value from a lazy ByteString.
If this fails due to incomplete or invalid input, Nothing is
returned.
The input must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses and performs conversion immediately. See
json' for details.
decodeFileStrict :: FromJSON a => FilePath -> IO (Maybe a) #
Efficiently deserialize a JSON value from a file.
If this fails due to incomplete or invalid input, Nothing is
returned.
The input file's content must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses immediately, but defers conversion. See
json for details.
decodeStrict :: FromJSON a => ByteString -> Maybe a #
Efficiently deserialize a JSON value from a strict ByteString.
If this fails due to incomplete or invalid input, Nothing is
returned.
The input must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses immediately, but defers conversion. See
json for details.
decode :: FromJSON a => ByteString -> Maybe a #
Efficiently deserialize a JSON value from a lazy ByteString.
If this fails due to incomplete or invalid input, Nothing is
returned.
The input must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses immediately, but defers conversion. See
json for details.
encodeFile :: ToJSON a => FilePath -> a -> IO () #
Efficiently serialize a JSON value as a lazy ByteString and write it to a file.
encode :: ToJSON a => a -> ByteString #
Efficiently serialize a JSON value as a lazy ByteString.
This is implemented in terms of the ToJSON class's toEncoding method.
type GToEncoding = GToJSON Encoding #
toEncoding2 :: (ToJSON2 f, ToJSON a, ToJSON b) => f a b -> Encoding #
Lift the standard toEncoding function through the type constructor.
toJSON2 :: (ToJSON2 f, ToJSON a, ToJSON b) => f a b -> Value #
Lift the standard toJSON function through the type constructor.
toEncoding1 :: (ToJSON1 f, ToJSON a) => f a -> Encoding #
Lift the standard toEncoding function through the type constructor.
toJSON1 :: (ToJSON1 f, ToJSON a) => f a -> Value #
Lift the standard toJSON function through the type constructor.
genericLiftToEncoding :: (Generic1 f, GToJSON Encoding One (Rep1 f)) => Options -> (a -> Encoding) -> ([a] -> Encoding) -> f a -> Encoding #
A configurable generic JSON encoder. This function applied to
defaultOptions is used as the default for liftToEncoding when the type
is an instance of Generic1.
genericToEncoding :: (Generic a, GToJSON Encoding Zero (Rep a)) => Options -> a -> Encoding #
A configurable generic JSON encoder. This function applied to
defaultOptions is used as the default for toEncoding when the type
is an instance of Generic.
genericLiftToJSON :: (Generic1 f, GToJSON Value One (Rep1 f)) => Options -> (a -> Value) -> ([a] -> Value) -> f a -> Value #
A configurable generic JSON creator. This function applied to
defaultOptions is used as the default for liftToJSON when the type
is an instance of Generic1.
genericToJSON :: (Generic a, GToJSON Value Zero (Rep a)) => Options -> a -> Value #
A configurable generic JSON creator. This function applied to
defaultOptions is used as the default for toJSON when the type
is an instance of Generic.
A type that can be converted to JSON.
Instances in general must specify toJSON and should (but don't need
to) specify toEncoding.
An example type and instance:
-- Allow ourselves to writeTextliterals. {-# LANGUAGE OverloadedStrings #-} data Coord = Coord { x :: Double, y :: Double } instanceToJSONCoord wheretoJSON(Coord x y) =object["x".=x, "y".=y]toEncoding(Coord x y) =pairs("x".=x<>"y".=y)
Instead of manually writing your ToJSON instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for
toJSON.
To use the second, simply add a deriving clause to your
datatype and declare a GenericToJSON instance. If you require nothing other than
defaultOptions, it is sufficient to write (and this is the only
alternative where the default toJSON implementation is sufficient):
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
data Coord = Coord { x :: Double, y :: Double } deriving Generic
instance ToJSON Coord where
toEncoding = genericToEncoding defaultOptions
If on the other hand you wish to customize the generic decoding, you have to implement both methods:
customOptions =defaultOptions{fieldLabelModifier=maptoUpper} instanceToJSONCoord wheretoJSON=genericToJSONcustomOptionstoEncoding=genericToEncodingcustomOptions
Previous versions of this library only had the toJSON method. Adding
toEncoding had to reasons:
- toEncoding is more efficient for the common case that the output of
toJSONis directly serialized to aByteString. Further, expressing either method in terms of the other would be non-optimal. - The choice of defaults allows a smooth transition for existing users:
Existing instances that do not define
toEncodingstill compile and have the correct semantics. This is ensured by making the default implementation oftoEncodingusetoJSON. This produces correct results, but since it performs an intermediate conversion to aValue, it will be less efficient than directly emitting anEncoding. (this also means that specifying nothing more thaninstance ToJSON Coordwould be sufficient as a generically decoding instance, but there probably exists no good reason to not specifytoEncodingin new instances.)
Methods
Convert a Haskell value to a JSON-friendly intermediate type.
toEncoding :: a -> Encoding #
Encode a Haskell value as JSON.
The default implementation of this method creates an
intermediate Value using toJSON. This provides
source-level compatibility for people upgrading from older
versions of this library, but obviously offers no performance
advantage.
To benefit from direct encoding, you must provide an
implementation for this method. The easiest way to do so is by
having your types implement Generic using the DeriveGeneric
extension, and then have GHC generate a method body as follows.
instanceToJSONCoord wheretoEncoding=genericToEncodingdefaultOptions
toJSONList :: [a] -> Value #
toEncodingList :: [a] -> Encoding #
Instances
A key-value pair for encoding a JSON object.
Minimal complete definition
Typeclass for types that can be used as the key of a map-like container
(like Map or HashMap). For example, since Text has a ToJSONKey
instance and Char has a ToJSON instance, we can encode a value of
type Map Text Char:
>>>LBC8.putStrLn $ encode $ Map.fromList [("foo" :: Text, 'a')]{"foo":"a"}
Since Int also has a ToJSONKey instance, we can similarly write:
>>>LBC8.putStrLn $ encode $ Map.fromList [(5 :: Int, 'a')]{"5":"a"}
JSON documents only accept strings as object keys. For any type
from base that has a natural textual representation, it can be
expected that its ToJSONKey instance will choose that representation.
For data types that lack a natural textual representation, an alternative is provided. The map-like container is represented as a JSON array instead of a JSON object. Each value in the array is an array with exactly two values. The first is the key and the second is the value.
For example, values of type '[Text]' cannot be encoded to a
string, so a Map with keys of type '[Text]' is encoded as follows:
>>>LBC8.putStrLn $ encode $ Map.fromList [(["foo","bar","baz" :: Text], 'a')][[["foo","bar","baz"],"a"]]
The default implementation of ToJSONKey chooses this method of
encoding a key, using the ToJSON instance of the type.
To use your own data type as the key in a map, all that is needed
is to write a ToJSONKey (and possibly a FromJSONKey) instance
for it. If the type cannot be trivially converted to and from Text,
it is recommended that ToJSONKeyValue is used. Since the default
implementations of the typeclass methods can build this from a
ToJSON instance, there is nothing that needs to be written:
data Foo = Foo { fooAge :: Int, fooName :: Text }
deriving (Eq,Ord,Generic)
instance ToJSON Foo
instance ToJSONKey FooThat's it. We can now write:
>>>let m = Map.fromList [(Foo 4 "bar",'a'),(Foo 6 "arg",'b')]>>>LBC8.putStrLn $ encode m[[{"fooName":"bar","fooAge":4},"a"],[{"fooName":"arg","fooAge":6},"b"]]
The next case to consider is if we have a type that is a
newtype wrapper around Text. The recommended approach is to use
generalized newtype deriving:
newtype RecordId = RecordId { getRecordId :: Text}
deriving (Eq,Ord,ToJSONKey)Then we may write:
>>>LBC8.putStrLn $ encode $ Map.fromList [(RecordId "abc",'a')]{"abc":"a"}
Simple sum types are a final case worth considering. Suppose we have:
data Color = Red | Green | Blue deriving (Show,Read,Eq,Ord)
It is possible to get the ToJSONKey instance for free as we did
with Foo. However, in this case, we have a natural way to go to
and from Text that does not require any escape sequences. So, in
this example, ToJSONKeyText will be used instead of ToJSONKeyValue.
The Show instance can be used to help write ToJSONKey:
instance ToJSONKey Color where
toJSONKey = ToJSONKeyText f g
where f = Text.pack . show
g = text . Text.pack . show
-- text function is from Data.Aeson.EncodingThe situation of needing to turning function a -> Text into
a ToJSONKeyFunction is common enough that a special combinator
is provided for it. The above instance can be rewritten as:
instance ToJSONKey Color where toJSONKey = toJSONKeyText (Text.pack . show)
The performance of the above instance can be improved by
not using String as an intermediate step when converting to
Text. One option for improving performance would be to use
template haskell machinery from the text-show package. However,
even with the approach, the Encoding (a wrapper around a bytestring
builder) is generated by encoding the Text to a ByteString,
an intermediate step that could be avoided. The fastest possible
implementation would be:
-- Assuming that OverloadedStrings is enabled
instance ToJSONKey Color where
toJSONKey = ToJSONKeyText f g
where f x = case x of {Red -> "Red";Green ->"Green";Blue -> "Blue"}
g x = case x of {Red -> text "Red";Green -> text "Green";Blue -> text "Blue"}
-- text function is from Data.Aeson.EncodingThis works because GHC can lift the encoded values out of the case statements, which means that they are only evaluated once. This approach should only be used when there is a serious need to maximize performance.
Methods
toJSONKey :: ToJSONKeyFunction a #
Strategy for rendering the key for a map-like container.
toJSONKeyList :: ToJSONKeyFunction [a] #
Instances
data ToJSONKeyFunction a #
Constructors
| ToJSONKeyText !(a -> Text) !(a -> Encoding' Text) | key is encoded to string, produces object |
| ToJSONKeyValue !(a -> Value) !(a -> Encoding) | key is encoded to value, produces array |
class ToJSON1 (f :: * -> *) where #
Lifting of the ToJSON class to unary type constructors.
Instead of manually writing your ToJSON1 instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for
toJSON1.
To use the second, simply add a deriving clause to your
datatype and declare a Generic1ToJSON1 instance for your datatype without giving
definitions for liftToJSON or liftToEncoding.
For example:
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
data Pair = Pair { pairFst :: a, pairSnd :: b } deriving Generic1
instance ToJSON a => ToJSON1 (Pair a)
If the default implementation doesn't give exactly the results you want,
you can customize the generic encoding with only a tiny amount of
effort, using genericLiftToJSON and genericLiftToEncoding with
your preferred Options:
customOptions =defaultOptions{fieldLabelModifier=maptoUpper} instanceToJSONa =>ToJSON1(Pair a) whereliftToJSON=genericLiftToJSONcustomOptionsliftToEncoding=genericLiftToEncodingcustomOptions
See also ToJSON.
Methods
liftToJSON :: (a -> Value) -> ([a] -> Value) -> f a -> Value #
liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [f a] -> Value #
liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> f a -> Encoding #
liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [f a] -> Encoding #
Instances
| ToJSON1 [] | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> [a] -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [[a]] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> [a] -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [[a]] -> Encoding # | |
| ToJSON1 Maybe | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Maybe a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Maybe a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Maybe a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Maybe a] -> Encoding # | |
| ToJSON1 Min | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Min a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Min a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Min a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Min a] -> Encoding # | |
| ToJSON1 Max | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Max a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Max a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Max a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Max a] -> Encoding # | |
| ToJSON1 First | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> First a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [First a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> First a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [First a] -> Encoding # | |
| ToJSON1 Last | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Last a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Last a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Last a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Last a] -> Encoding # | |
| ToJSON1 WrappedMonoid | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> WrappedMonoid a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [WrappedMonoid a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> WrappedMonoid a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [WrappedMonoid a] -> Encoding # | |
| ToJSON1 Option | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Option a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Option a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Option a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Option a] -> Encoding # | |
| ToJSON1 Identity | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Identity a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Identity a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Identity a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Identity a] -> Encoding # | |
| ToJSON1 First | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> First a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [First a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> First a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [First a] -> Encoding # | |
| ToJSON1 Last | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Last a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Last a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Last a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Last a] -> Encoding # | |
| ToJSON1 Dual | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Dual a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Dual a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Dual a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Dual a] -> Encoding # | |
| ToJSON1 NonEmpty | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> NonEmpty a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [NonEmpty a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> NonEmpty a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [NonEmpty a] -> Encoding # | |
| ToJSON1 IntMap | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> IntMap a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [IntMap a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> IntMap a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [IntMap a] -> Encoding # | |
| ToJSON1 Tree | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Tree a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Tree a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Tree a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Tree a] -> Encoding # | |
| ToJSON1 Seq | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Seq a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Seq a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Seq a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Seq a] -> Encoding # | |
| ToJSON1 Set | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Set a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Set a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Set a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Set a] -> Encoding # | |
| ToJSON1 DList | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> DList a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [DList a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> DList a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [DList a] -> Encoding # | |
| ToJSON1 HashSet | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> HashSet a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [HashSet a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> HashSet a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [HashSet a] -> Encoding # | |
| ToJSON1 Vector | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Vector a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Vector a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Vector a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Vector a] -> Encoding # | |
| ToJSON a => ToJSON1 (Either a) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Either a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Either a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Either a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Either a a0] -> Encoding # | |
| ToJSON a => ToJSON1 ((,) a) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, a0)] -> Encoding # | |
| ToJSONKey k => ToJSON1 (HashMap k) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> HashMap k a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [HashMap k a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> HashMap k a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [HashMap k a] -> Encoding # | |
| ToJSONKey k => ToJSON1 (Map k) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Map k a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Map k a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Map k a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Map k a] -> Encoding # | |
| ToJSON1 (Proxy :: * -> *) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Proxy a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Proxy a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Proxy a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Proxy a] -> Encoding # | |
| (ToJSON a, ToJSON b) => ToJSON1 ((,,) a b) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, a0)] -> Encoding # | |
| ToJSON a => ToJSON1 (Const a :: * -> *) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Const a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Const a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Const a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Const a a0] -> Encoding # | |
| ToJSON1 (Tagged a) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Tagged a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Tagged a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Tagged a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Tagged a a0] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c) => ToJSON1 ((,,,) a b c) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, a0)] -> Encoding # | |
| (ToJSON1 f, ToJSON1 g) => ToJSON1 (Product f g) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Product f g a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Product f g a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Product f g a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Product f g a] -> Encoding # | |
| (ToJSON1 f, ToJSON1 g) => ToJSON1 (Sum f g) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Sum f g a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Sum f g a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Sum f g a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Sum f g a] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON1 ((,,,,) a b c d) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, a0)] -> Encoding # | |
| (ToJSON1 f, ToJSON1 g) => ToJSON1 (Compose f g) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> Compose f g a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Compose f g a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Compose f g a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Compose f g a] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON1 ((,,,,,) a b c d e) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, a0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON1 ((,,,,,,) a b c d e f) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, a0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON1 ((,,,,,,,) a b c d e f g) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, a0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON1 ((,,,,,,,,) a b c d e f g h) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, a0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON1 ((,,,,,,,,,) a b c d e f g h i) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, a0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON1 ((,,,,,,,,,,) a b c d e f g h i j) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, a0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON1 ((,,,,,,,,,,,) a b c d e f g h i j k) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, a0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, a0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n) => ToJSON1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0)] -> Encoding # | |
class ToJSON2 (f :: * -> * -> *) where #
Lifting of the ToJSON class to binary type constructors.
Instead of manually writing your ToJSON2 instance, Data.Aeson.TH
provides Template Haskell functions which will derive an instance at compile time.
The compiler cannot provide a default generic implementation for liftToJSON2,
unlike toJSON and liftToJSON.
Minimal complete definition
Methods
liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> f a b -> Value #
liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [f a b] -> Value #
liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> f a b -> Encoding #
liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [f a b] -> Encoding #
Instances
| ToJSON2 Either | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> Either a b -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [Either a b] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> Either a b -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [Either a b] -> Encoding # | |
| ToJSON2 (,) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> (a, b) -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [(a, b)] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> (a, b) -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [(a, b)] -> Encoding # | |
| ToJSON a => ToJSON2 ((,,) a) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b -> Value) -> ([b] -> Value) -> (a, a0, b) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b -> Value) -> ([b] -> Value) -> [(a, a0, b)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> (a, a0, b) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [(a, a0, b)] -> Encoding # | |
| ToJSON2 (Const :: * -> * -> *) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> Const a b -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [Const a b] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> Const a b -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [Const a b] -> Encoding # | |
| ToJSON2 (Tagged :: * -> * -> *) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> Tagged a b -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [Tagged a b] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> Tagged a b -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [Tagged a b] -> Encoding # | |
| (ToJSON a, ToJSON b) => ToJSON2 ((,,,) a b) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c) => ToJSON2 ((,,,,) a b c) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON2 ((,,,,,) a b c d) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON2 ((,,,,,,) a b c d e) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON2 ((,,,,,,,) a b c d e f) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON2 ((,,,,,,,,) a b c d e f g) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON2 ((,,,,,,,,,) a b c d e f g h) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON2 ((,,,,,,,,,,) a b c d e f g h i) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, i, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, i, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON2 ((,,,,,,,,,,,) a b c d e f g h i j) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON2 ((,,,,,,,,,,,,) a b c d e f g h i j k) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON2 ((,,,,,,,,,,,,,) a b c d e f g h i j k l) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, a0, b0)] -> Encoding # | |
| (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON2 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m) | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0)] -> Encoding # | |
fromEncoding :: Encoding' tag -> Builder #
Acquire the underlying bytestring builder.
A series of values that, when encoded, should be separated by
commas. Since 0.11.0.0, the .= operator is overloaded to create
either (Text, Value) or Series. You can use Series when
encoding directly to a bytestring builder as in the following
example:
toEncoding (Person name age) = pairs ("name" .= name <> "age" .= age)(.!=) :: Parser (Maybe a) -> a -> Parser a #
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"
(.:?) :: FromJSON a => Object -> Text -> Parser (Maybe a) #
Retrieve the value associated with the given key of an Object. The
result is Nothing if the key is not present or if its value is Null,
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. If the key and
value are mandatory, use .: instead.
(.:) :: FromJSON a => Object -> Text -> Parser a #
Retrieve the value associated with the given key of an Object.
The result is empty if the key is not present or the value cannot
be converted to the desired type.
This accessor is appropriate if the key and value must be present
in an object for it to be valid. If the key and value are
optional, use .:? instead.
fromJSON :: FromJSON a => Value -> Result a #
Convert a value from JSON, failing if the types do not match.
withEmbeddedJSON :: String -> (Value -> Parser a) -> Value -> Parser a #
Decode a nested JSON-encoded string.
withBool :: String -> (Bool -> Parser a) -> Value -> Parser a #
applies withBool expected f valuef to the Bool when value is a
Bool and fails using otherwise.typeMismatch expected
withScientific :: String -> (Scientific -> Parser a) -> Value -> Parser a #
applies withScientific expected f valuef to the Scientific number
when value is a Number and fails using
otherwise.
.
Warning: If you are converting from a scientific to an unbounded
type such as typeMismatch expectedInteger you may want to add a restriction on the
size of the exponent (see withBoundedScientific) to prevent
malicious input from filling up the memory of the target system.
withArray :: String -> (Array -> Parser a) -> Value -> Parser a #
applies withArray expected f valuef to the Array when value is
an Array and fails using otherwise.typeMismatch expected
withText :: String -> (Text -> Parser a) -> Value -> Parser a #
applies withText expected f valuef to the Text when value is a
String and fails using otherwise.typeMismatch expected
withObject :: String -> (Object -> Parser a) -> Value -> Parser a #
applies withObject expected f valuef to the Object when value
is an Object and fails using otherwise.typeMismatch expected
parseJSON2 :: (FromJSON2 f, FromJSON a, FromJSON b) => Value -> Parser (f a b) #
Lift the standard parseJSON function through the type constructor.
parseJSON1 :: (FromJSON1 f, FromJSON a) => Value -> Parser (f a) #
Lift the standard parseJSON function through the type constructor.
genericLiftParseJSON :: (Generic1 f, GFromJSON One (Rep1 f)) => Options -> (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (f a) #
A configurable generic JSON decoder. This function applied to
defaultOptions is used as the default for liftParseJSON when the
type is an instance of Generic1.
genericParseJSON :: (Generic a, GFromJSON Zero (Rep a)) => Options -> Value -> Parser a #
A configurable generic JSON decoder. This function applied to
defaultOptions is used as the default for parseJSON when the
type is an instance of Generic.
class GFromJSON arity (f :: * -> *) where #
Class of generic representation types that can be converted from JSON.
Minimal complete definition
Methods
gParseJSON :: Options -> FromArgs arity a -> Value -> Parser (f a) #
This method (applied to defaultOptions) is used as the
default generic implementation of parseJSON (if the arity is Zero)
or liftParseJSON (if the arity is One).
Instances
| GFromJSON One Par1 | |
Defined in Data.Aeson.Types.FromJSON | |
| GFromJSON arity (U1 :: * -> *) | |
Defined in Data.Aeson.Types.FromJSON | |
| FromJSON1 f => GFromJSON One (Rec1 f) | |
Defined in Data.Aeson.Types.FromJSON | |
| (ConsFromJSON arity a, AllNullary (C1 c a) allNullary, ParseSum arity (C1 c a) allNullary) => GFromJSON arity (D1 d (C1 c a)) | |
Defined in Data.Aeson.Types.FromJSON | |
| ConsFromJSON arity a => GFromJSON arity (C1 c a) | |
Defined in Data.Aeson.Types.FromJSON | |
| (AllNullary (a :+: b) allNullary, ParseSum arity (a :+: b) allNullary) => GFromJSON arity (a :+: b) | |
Defined in Data.Aeson.Types.FromJSON | |
| FromJSON a => GFromJSON arity (K1 i a :: * -> *) | |
Defined in Data.Aeson.Types.FromJSON | |
| (FromProduct arity a, FromProduct arity b, ProductSize a, ProductSize b) => GFromJSON arity (a :*: b) | |
Defined in Data.Aeson.Types.FromJSON | |
| GFromJSON arity a => GFromJSON arity (M1 i c a) | |
Defined in Data.Aeson.Types.FromJSON | |
| (FromJSON1 f, GFromJSON One g) => GFromJSON One (f :.: g) | |
Defined in Data.Aeson.Types.FromJSON | |
A type that can be converted from JSON, with the possibility of failure.
In many cases, you can get the compiler to generate parsing code for you (see below). To begin, let's cover writing an instance by hand.
There are various reasons a conversion could fail. For example, an
Object could be missing a required key, an Array could be of
the wrong size, or a value could be of an incompatible type.
The basic ways to signal a failed conversion are as follows:
emptyandmzerowork, but are terse and uninformative;failyields a custom error message;typeMismatchproduces an informative message for cases when the value encountered is not of the expected type.
An example type and instance using typeMismatch:
-- Allow ourselves to writeTextliterals. {-# LANGUAGE OverloadedStrings #-} data Coord = Coord { x :: Double, y :: Double } instanceFromJSONCoord whereparseJSON(Objectv) = Coord<$>v.:"x"<*>v.:"y" -- We do not expect a non-Objectvalue here. -- We could usemzeroto fail, buttypeMismatch-- gives a much more informative error message.parseJSONinvalid =typeMismatch"Coord" invalid
For this common case of only being concerned with a single
type of JSON value, the functions withObject, withNumber, etc.
are provided. Their use is to be preferred when possible, since
they are more terse. Using withObject, we can rewrite the above instance
(assuming the same language extension and data type) as:
instanceFromJSONCoord whereparseJSON=withObject"Coord" $ \v -> Coord<$>v.:"x"<*>v.:"y"
Instead of manually writing your FromJSON instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for
parseJSON.
To use the second, simply add a deriving clause to your
datatype and declare a GenericFromJSON instance for your datatype without giving
a definition for parseJSON.
For example, the previous example can be simplified to just:
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
data Coord = Coord { x :: Double, y :: Double } deriving Generic
instance FromJSON Coord
The default implementation will be equivalent to
parseJSON = ; If you need different
options, you can customize the generic decoding by defining:genericParseJSON defaultOptions
customOptions =defaultOptions{fieldLabelModifier=maptoUpper} instanceFromJSONCoord whereparseJSON=genericParseJSONcustomOptions
Instances
class FromJSONKey a where #
Read the docs for ToJSONKey first. This class is a conversion
in the opposite direction. If you have a newtype wrapper around Text,
the recommended way to define instances is with generalized newtype deriving:
newtype SomeId = SomeId { getSomeId :: Text }
deriving (Eq,Ord,Hashable,FromJSONKey)Methods
fromJSONKey :: FromJSONKeyFunction a #
Strategy for parsing the key of a map-like container.
fromJSONKeyList :: FromJSONKeyFunction [a] #
Instances
data FromJSONKeyFunction a #
This type is related to ToJSONKeyFunction. If FromJSONKeyValue is used in the
FromJSONKey instance, then ToJSONKeyValue should be used in the ToJSONKey
instance. The other three data constructors for this type all correspond to
ToJSONKeyText. Strictly speaking, FromJSONKeyTextParser is more powerful than
FromJSONKeyText, which is in turn more powerful than FromJSONKeyCoerce.
For performance reasons, these exist as three options instead of one.
Constructors
| FromJSONKeyCoerce !(CoerceText a) | uses |
| FromJSONKeyText !(Text -> a) | conversion from |
| FromJSONKeyTextParser !(Text -> Parser a) | conversion from |
| FromJSONKeyValue !(Value -> Parser a) | conversion for non-textual keys |
Instances
| Functor FromJSONKeyFunction | Only law abiding up to interpretation |
Defined in Data.Aeson.Types.FromJSON Methods fmap :: (a -> b) -> FromJSONKeyFunction a -> FromJSONKeyFunction b # (<$) :: a -> FromJSONKeyFunction b -> FromJSONKeyFunction a # | |
class FromJSON1 (f :: * -> *) where #
Lifting of the FromJSON class to unary type constructors.
Instead of manually writing your FromJSON1 instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for
liftParseJSON.
To use the second, simply add a deriving clause to your
datatype and declare a Generic1FromJSON1 instance for your datatype without giving
a definition for liftParseJSON.
For example:
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
data Pair a b = Pair { pairFst :: a, pairSnd :: b } deriving Generic1
instance FromJSON a => FromJSON1 (Pair a)
If the default implementation doesn't give exactly the results you want,
you can customize the generic decoding with only a tiny amount of
effort, using genericLiftParseJSON with your preferred Options:
customOptions =defaultOptions{fieldLabelModifier=maptoUpper} instanceFromJSONa =>FromJSON1(Pair a) whereliftParseJSON=genericLiftParseJSONcustomOptions
Methods
liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (f a) #
liftParseJSONList :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [f a] #
Instances
class FromJSON2 (f :: * -> * -> *) where #
Lifting of the FromJSON class to binary type constructors.
Instead of manually writing your FromJSON2 instance, Data.Aeson.TH
provides Template Haskell functions which will derive an instance at compile time.
Minimal complete definition
Methods
liftParseJSON2 :: (Value -> Parser a) -> (Value -> Parser [a]) -> (Value -> Parser b) -> (Value -> Parser [b]) -> Value -> Parser (f a b) #
liftParseJSONList2 :: (Value -> Parser a) -> (Value -> Parser [a]) -> (Value -> Parser b) -> (Value -> Parser [b]) -> Value -> Parser [f a b] #
Instances
| FromJSON2 Either | |
Defined in Data.Aeson.Types.FromJSON | |
| FromJSON2 (,) | |
Defined in Data.Aeson.Types.FromJSON | |
| FromJSON a => FromJSON2 ((,,) a) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b) -> (Value -> Parser [b]) -> Value -> Parser (a, a0, b) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b) -> (Value -> Parser [b]) -> Value -> Parser [(a, a0, b)] # | |
| FromJSON2 (Const :: * -> * -> *) | |
Defined in Data.Aeson.Types.FromJSON | |
| FromJSON2 (Tagged :: * -> * -> *) | |
Defined in Data.Aeson.Types.FromJSON | |
| (FromJSON a, FromJSON b) => FromJSON2 ((,,,) a b) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c) => FromJSON2 ((,,,,) a b c) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON2 ((,,,,,) a b c d) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e) => FromJSON2 ((,,,,,,) a b c d e) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f) => FromJSON2 ((,,,,,,,) a b c d e f) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g) => FromJSON2 ((,,,,,,,,) a b c d e f g) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h) => FromJSON2 ((,,,,,,,,,) a b c d e f g h) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i) => FromJSON2 ((,,,,,,,,,,) a b c d e f g h i) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, i, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, i, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j) => FromJSON2 ((,,,,,,,,,,,) a b c d e f g h i j) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, i, j, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, i, j, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k) => FromJSON2 ((,,,,,,,,,,,,) a b c d e f g h i j k) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l) => FromJSON2 ((,,,,,,,,,,,,,) a b c d e f g h i j k l) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l, a0, b0)] # | |
| (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m) => FromJSON2 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m) | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0)] # | |
Parse a top-level JSON value.
This is a strict version of json which avoids building up thunks
during parsing; it performs all conversions immediately. Prefer
this version if most of the JSON data needs to be accessed.
This function is an alias for value'. In aeson 0.8 and earlier, it
parsed only object or array types, in conformance with the
now-obsolete RFC 4627.
Parse a top-level JSON value.
The conversion of a parsed value to a Haskell value is deferred until the Haskell value is needed. This may improve performance if only a subset of the results of conversions are needed, but at a cost in thunk allocation.
This function is an alias for value. In aeson 0.8 and earlier, it
parsed only object or array types, in conformance with the
now-obsolete RFC 4627.
camelTo2 :: Char -> String -> String #
Better version of camelTo. Example where it works better:
camelTo '_' 'CamelAPICase' == "camel_apicase" camelTo2 '_' 'CamelAPICase' == "camel_api_case"
defaultTaggedObject :: SumEncoding #
Default TaggedObject SumEncoding options:
defaultTaggedObject =TaggedObject{tagFieldName= "tag" ,contentsFieldName= "contents" }
Default encoding Options:
Options{fieldLabelModifier= id ,constructorTagModifier= id ,allNullaryToStringTag= True ,omitNothingFields= False ,sumEncoding=defaultTaggedObject,unwrapUnaryRecords= False ,tagSingleConstructors= False }
The result of running a Parser.
Instances
| Monad Result | |
| Functor Result | |
| MonadFail Result | |
Defined in Data.Aeson.Types.Internal | |
| Applicative Result | |
| Foldable Result | |
Defined in Data.Aeson.Types.Internal Methods fold :: Monoid m => Result m -> m # foldMap :: Monoid m => (a -> m) -> Result a -> m # foldr :: (a -> b -> b) -> b -> Result a -> b # foldr' :: (a -> b -> b) -> b -> Result a -> b # foldl :: (b -> a -> b) -> b -> Result a -> b # foldl' :: (b -> a -> b) -> b -> Result a -> b # foldr1 :: (a -> a -> a) -> Result a -> a # foldl1 :: (a -> a -> a) -> Result a -> a # elem :: Eq a => a -> Result a -> Bool # maximum :: Ord a => Result a -> a # minimum :: Ord a => Result a -> a # | |
| Traversable Result | |
| Alternative Result | |
| MonadPlus Result | |
| Eq a => Eq (Result a) | |
| Show a => Show (Result a) | |
| Semigroup (Result a) | |
| Monoid (Result a) | |
| NFData a => NFData (Result a) | |
Defined in Data.Aeson.Types.Internal | |
A JSON value represented as a Haskell value.
Instances
| Eq Value | |
| Data Value | |
Defined in Data.Aeson.Types.Internal Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Value -> c Value # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Value # dataTypeOf :: Value -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Value) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Value) # gmapT :: (forall b. Data b => b -> b) -> Value -> Value # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r # gmapQ :: (forall d. Data d => d -> u) -> Value -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Value -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Value -> m Value # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value # | |
| Read Value | |
| Show Value | |
| IsString Value | |
Defined in Data.Aeson.Types.Internal Methods fromString :: String -> Value # | |
| Generic Value | |
| Lift Value | |
| Hashable Value | |
Defined in Data.Aeson.Types.Internal | |
| ToJSON Value | |
Defined in Data.Aeson.Types.ToJSON | |
| KeyValue Pair | |
| FromJSON Value | |
| NFData Value | |
Defined in Data.Aeson.Types.Internal | |
| FromString Encoding | |
Defined in Data.Aeson.Types.ToJSON Methods fromString :: String -> Encoding | |
| FromString Value | |
Defined in Data.Aeson.Types.ToJSON Methods fromString :: String -> Value | |
| GToJSON Encoding arity (U1 :: * -> *) | |
| GToJSON Value arity (U1 :: * -> *) | |
| ToJSON1 f => GToJSON Encoding One (Rec1 f) | |
| ToJSON1 f => GToJSON Value One (Rec1 f) | |
| ToJSON a => GToJSON Encoding arity (K1 i a :: * -> *) | |
| (EncodeProduct arity a, EncodeProduct arity b) => GToJSON Encoding arity (a :*: b) | |
| ToJSON a => GToJSON Value arity (K1 i a :: * -> *) | |
| (WriteProduct arity a, WriteProduct arity b, ProductSize a, ProductSize b) => GToJSON Value arity (a :*: b) | |
| (ToJSON1 f, GToJSON Encoding One g) => GToJSON Encoding One (f :.: g) | |
| (ToJSON1 f, GToJSON Value One g) => GToJSON Value One (f :.: g) | |
| FromPairs Value (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
| v ~ Value => KeyValuePair v (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
| (GToJSON Encoding arity a, ConsToJSON Encoding arity a, Constructor c) => SumToJSON' TwoElemArray Encoding arity (C1 c a) | |
Defined in Data.Aeson.Types.ToJSON | |
| (GToJSON Value arity a, ConsToJSON Value arity a, Constructor c) => SumToJSON' TwoElemArray Value arity (C1 c a) | |
Defined in Data.Aeson.Types.ToJSON | |
| type Rep Value | |
Defined in Data.Aeson.Types.Internal type Rep Value = D1 (MetaData "Value" "Data.Aeson.Types.Internal" "aeson-1.4.0.0-5MIZAct1Yn73Zmup8jk6Ca" False) ((C1 (MetaCons "Object" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Object)) :+: (C1 (MetaCons "Array" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Array)) :+: C1 (MetaCons "String" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text)))) :+: (C1 (MetaCons "Number" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Scientific)) :+: (C1 (MetaCons "Bool" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Bool)) :+: C1 (MetaCons "Null" PrefixI False) (U1 :: * -> *)))) | |
newtype DotNetTime #
A newtype wrapper for UTCTime that uses the same non-standard
serialization format as Microsoft .NET, whose
System.DateTime
type is by default serialized to JSON as in the following example:
/Date(1302547608878)/
The number represents milliseconds since the Unix epoch.
Constructors
| DotNetTime | |
Fields
| |
Instances
Options that specify how to encode/decode your datatype to/from JSON.
Options can be set using record syntax on defaultOptions with the fields
below.
data SumEncoding #
Specifies how to encode constructors of a sum datatype.
Constructors
| TaggedObject | A constructor will be encoded to an object with a field
|
Fields | |
| UntaggedValue | Constructor names won't be encoded. Instead only the contents of the constructor will be encoded as if the type had a single constructor. JSON encodings have to be disjoint for decoding to work properly. When decoding, constructors are tried in the order of definition. If some encodings overlap, the first one defined will succeed. Note: Nullary constructors are encoded as strings (using
Note: Only the last error is kept when decoding, so in the case of malformed JSON, only an error for the last constructor will be reported. |
| ObjectWithSingleField | A constructor will be encoded to an object with a single
field named after the constructor tag (modified by the
|
| TwoElemArray | A constructor will be encoded to a 2-element array where the
first element is the tag of the constructor (modified by the
|
Instances
| Eq SumEncoding | |
Defined in Data.Aeson.Types.Internal | |
| Show SumEncoding | |
Defined in Data.Aeson.Types.Internal Methods showsPrec :: Int -> SumEncoding -> ShowS # show :: SumEncoding -> String # showList :: [SumEncoding] -> ShowS # | |
A type-level indicator that ToJSON1 or FromJSON1 is being derived generically.
Instances
| GFromJSON One Par1 | |
Defined in Data.Aeson.Types.FromJSON | |
| GToJSON enc One Par1 | |
| ToJSON1 f => GToJSON Encoding One (Rec1 f) | |
| ToJSON1 f => GToJSON Value One (Rec1 f) | |
| (ToJSON1 f, GToJSON Encoding One g) => GToJSON Encoding One (f :.: g) | |
| (ToJSON1 f, GToJSON Value One g) => GToJSON Value One (f :.: g) | |
| FromJSON1 f => GFromJSON One (Rec1 f) | |
Defined in Data.Aeson.Types.FromJSON | |
| (FromJSON1 f, GFromJSON One g) => GFromJSON One (f :.: g) | |
Defined in Data.Aeson.Types.FromJSON | |
catMaybes :: [Maybe a] -> [a] #
The catMaybes function takes a list of Maybes and returns
a list of all the Just values.
Examples
Basic usage:
>>>catMaybes [Just 1, Nothing, Just 3][1,3]
When constructing a list of Maybe values, catMaybes can be used
to return all of the "success" results (if the list is the result
of a map, then mapMaybe would be more appropriate):
>>>import Text.Read ( readMaybe )>>>[readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ][Just 1,Nothing,Just 3]>>>catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ][1,3]
fromDistinctDescList :: [(k, a)] -> Map k a #
O(n). Build a map from a descending list of distinct elements in linear time. The precondition is not checked.
fromDistinctDescList [(5,"a"), (3,"b")] == fromList [(3, "b"), (5, "a")] valid (fromDistinctDescList [(5,"a"), (3,"b")]) == True valid (fromDistinctDescList [(5,"a"), (3,"b"), (3,"a")]) == False
fromDistinctAscList :: [(k, a)] -> Map k a #
O(n). Build a map from an ascending list of distinct elements in linear time. The precondition is not checked.
fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] valid (fromDistinctAscList [(3,"b"), (5,"a")]) == True valid (fromDistinctAscList [(3,"b"), (5,"a"), (5,"b")]) == False
fromDescListWithKey :: Eq k => (k -> a -> a -> a) -> [(k, a)] -> Map k a #
O(n). Build a map from a descending list in linear time with a combining function for equal keys. The precondition (input list is descending) is not checked.
let f k a1 a2 = (show k) ++ ":" ++ a1 ++ a2 fromDescListWithKey f [(5,"a"), (5,"b"), (5,"b"), (3,"b")] == fromList [(3, "b"), (5, "5:b5:ba")] valid (fromDescListWithKey f [(5,"a"), (5,"b"), (5,"b"), (3,"b")]) == True valid (fromDescListWithKey f [(5,"a"), (3,"b"), (5,"b"), (5,"b")]) == False
fromAscListWithKey :: Eq k => (k -> a -> a -> a) -> [(k, a)] -> Map k a #
O(n). Build a map from an ascending list in linear time with a combining function for equal keys. The precondition (input list is ascending) is not checked.
let f k a1 a2 = (show k) ++ ":" ++ a1 ++ a2 fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b"), (5,"b")] == fromList [(3, "b"), (5, "5:b5:ba")] valid (fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b"), (5,"b")]) == True valid (fromAscListWithKey f [(5,"a"), (3,"b"), (5,"b"), (5,"b")]) == False
fromDescListWith :: Eq k => (a -> a -> a) -> [(k, a)] -> Map k a #
O(n). Build a map from a descending list in linear time with a combining function for equal keys. The precondition (input list is descending) is not checked.
fromDescListWith (++) [(5,"a"), (5,"b"), (3,"b")] == fromList [(3, "b"), (5, "ba")] valid (fromDescListWith (++) [(5,"a"), (5,"b"), (3,"b")]) == True valid (fromDescListWith (++) [(5,"a"), (3,"b"), (5,"b")]) == False
fromAscListWith :: Eq k => (a -> a -> a) -> [(k, a)] -> Map k a #
O(n). Build a map from an ascending list in linear time with a combining function for equal keys. The precondition (input list is ascending) is not checked.
fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")] valid (fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")]) == True valid (fromAscListWith (++) [(5,"a"), (3,"b"), (5,"b")]) == False
fromDescList :: Eq k => [(k, a)] -> Map k a #
O(n). Build a map from a descending list in linear time. The precondition (input list is descending) is not checked.
fromDescList [(5,"a"), (3,"b")] == fromList [(3, "b"), (5, "a")] fromDescList [(5,"a"), (5,"b"), (3,"a")] == fromList [(3, "b"), (5, "b")] valid (fromDescList [(5,"a"), (5,"b"), (3,"b")]) == True valid (fromDescList [(5,"a"), (3,"b"), (5,"b")]) == False
fromAscList :: Eq k => [(k, a)] -> Map k a #
O(n). Build a map from an ascending list in linear time. The precondition (input list is ascending) is not checked.
fromAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] fromAscList [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "b")] valid (fromAscList [(3,"b"), (5,"a"), (5,"b")]) == True valid (fromAscList [(5,"a"), (3,"b"), (5,"b")]) == False
fromListWithKey :: Ord k => (k -> a -> a -> a) -> [(k, a)] -> Map k a #
O(n*log n). Build a map from a list of key/value pairs with a combining function. See also fromAscListWithKey.
let f k a1 a2 = (show k) ++ a1 ++ a2 fromListWithKey f [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "3ab"), (5, "5a5ba")] fromListWithKey f [] == empty
fromListWith :: Ord k => (a -> a -> a) -> [(k, a)] -> Map k a #
O(n*log n). Build a map from a list of key/value pairs with a combining function. See also fromAscListWith.
fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")] fromListWith (++) [] == empty
fromList :: Ord k => [(k, a)] -> Map k a #
O(n*log n). Build a map from a list of key/value pairs. See also fromAscList.
If the list contains more than one value for the same key, the last value
for the key is retained.
If the keys of the list are ordered, linear-time implementation is used,
with the performance equal to fromDistinctAscList.
fromList [] == empty fromList [(5,"a"), (3,"b"), (5, "c")] == fromList [(5,"c"), (3,"b")] fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")]
fromSet :: (k -> a) -> Set k -> Map k a #
O(n). Build a map from a set of keys and a function which for each key computes its value.
fromSet (\k -> replicate k 'a') (Data.Set.fromList [3, 5]) == fromList [(5,"aaaaa"), (3,"aaa")] fromSet undefined Data.Set.empty == empty
mapKeysWith :: Ord k2 => (a -> a -> a) -> (k1 -> k2) -> Map k1 a -> Map k2 a #
O(n*log n).
is the map obtained by applying mapKeysWith c f sf to each key of s.
The size of the result may be smaller if f maps two or more distinct
keys to the same new key. In this case the associated values will be
combined using c. The value at the greater of the two original keys
is used as the first argument to c.
mapKeysWith (++) (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "cdab" mapKeysWith (++) (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "cdab"
mapAccumRWithKey :: (a -> k -> b -> (a, c)) -> a -> Map k b -> (a, Map k c) #
O(n). The function mapAccumR threads an accumulating
argument through the map in descending order of keys.
mapAccumWithKey :: (a -> k -> b -> (a, c)) -> a -> Map k b -> (a, Map k c) #
O(n). The function mapAccumWithKey threads an accumulating
argument through the map in ascending order of keys.
let f a k b = (a ++ " " ++ (show k) ++ "-" ++ b, b ++ "X")
mapAccumWithKey f "Everything:" (fromList [(5,"a"), (3,"b")]) == ("Everything: 3-b 5-a", fromList [(3, "bX"), (5, "aX")])mapAccum :: (a -> b -> (a, c)) -> a -> Map k b -> (a, Map k c) #
O(n). The function mapAccum threads an accumulating
argument through the map in ascending order of keys.
let f a b = (a ++ b, b ++ "X")
mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])traverseWithKey :: Applicative t => (k -> a -> t b) -> Map k a -> t (Map k b) #
O(n).
That is, it behaves much like a regular traverseWithKey f m == fromList $ traverse ((k, v) -> (v' -> v' seq (k,v')) $ f k v) (toList m)traverse except that the traversing
function also has access to the key associated with a value and the values are
forced before they are installed in the result map.
traverseWithKey (\k v -> if odd k then Just (succ v) else Nothing) (fromList [(1, 'a'), (5, 'e')]) == Just (fromList [(1, 'b'), (5, 'f')]) traverseWithKey (\k v -> if odd k then Just (succ v) else Nothing) (fromList [(2, 'c')]) == Nothing
mapWithKey :: (k -> a -> b) -> Map k a -> Map k b #
O(n). Map a function over all values in the map.
let f key x = (show key) ++ ":" ++ x mapWithKey f (fromList [(5,"a"), (3,"b")]) == fromList [(3, "3:b"), (5, "5:a")]
map :: (a -> b) -> Map k a -> Map k b #
O(n). Map a function over all values in the map.
map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
mapEitherWithKey :: (k -> a -> Either b c) -> Map k a -> (Map k b, Map k c) #
O(n). Map keys/values and separate the Left and Right results.
let f k a = if k < 5 then Left (k * 2) else Right (a ++ a)
mapEitherWithKey f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
== (fromList [(1,2), (3,6)], fromList [(5,"aa"), (7,"zz")])
mapEitherWithKey (\_ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
== (empty, fromList [(1,"x"), (3,"b"), (5,"a"), (7,"z")])mapEither :: (a -> Either b c) -> Map k a -> (Map k b, Map k c) #
O(n). Map values and separate the Left and Right results.
let f a = if a < "c" then Left a else Right a
mapEither f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
== (fromList [(3,"b"), (5,"a")], fromList [(1,"x"), (7,"z")])
mapEither (\ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
== (empty, fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])traverseMaybeWithKey :: Applicative f => (k -> a -> f (Maybe b)) -> Map k a -> f (Map k b) #
O(n). Traverse keys/values and collect the Just results.
Since: containers-0.5.8
mapMaybeWithKey :: (k -> a -> Maybe b) -> Map k a -> Map k b #
O(n). Map keys/values and collect the Just results.
let f k _ = if k < 5 then Just ("key : " ++ (show k)) else Nothing
mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key : 3"mapMaybe :: (a -> Maybe b) -> Map k a -> Map k b #
O(n). Map values and collect the Just results.
let f x = if x == "a" then Just "new a" else Nothing mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a"
mergeWithKey :: Ord k => (k -> a -> b -> Maybe c) -> (Map k a -> Map k c) -> (Map k b -> Map k c) -> Map k a -> Map k b -> Map k c #
O(n+m). An unsafe universal combining function.
WARNING: This function can produce corrupt maps and its results
may depend on the internal structures of its inputs. Users should
prefer merge or
mergeA.
When mergeWithKey is given three arguments, it is inlined to the call
site. You should therefore use mergeWithKey only to define custom
combining functions. For example, you could define unionWithKey,
differenceWithKey and intersectionWithKey as
myUnionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) id id m1 m2 myDifferenceWithKey f m1 m2 = mergeWithKey f id (const empty) m1 m2 myIntersectionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) (const empty) (const empty) m1 m2
When calling , a function combining two
mergeWithKey combine only1 only2Maps is created, such that
- if a key is present in both maps, it is passed with both corresponding
values to the
combinefunction. Depending on the result, the key is either present in the result with specified value, or is left out; - a nonempty subtree present only in the first map is passed to
only1and the output is added to the result; - a nonempty subtree present only in the second map is passed to
only2and the output is added to the result.
The only1 and only2 methods must return a map with a subset (possibly empty) of the keys of the given map.
The values can be modified arbitrarily. Most common variants of only1 and
only2 are id and , but for example const empty or
map f could be used for any filterWithKey ff.
intersectionWithKey :: Ord k => (k -> a -> b -> c) -> Map k a -> Map k b -> Map k c #
O(m*log(n/m + 1)), m <= n. Intersection with a combining function.
let f k al ar = (show k) ++ ":" ++ al ++ "|" ++ ar intersectionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "5:a|A"
intersectionWith :: Ord k => (a -> b -> c) -> Map k a -> Map k b -> Map k c #
O(m*log(n/m + 1)), m <= n. Intersection with a combining function.
intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA"
differenceWithKey :: Ord k => (k -> a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a #
O(n+m). Difference with a combining function. When two equal keys are
encountered, the combining function is applied to the key and both values.
If it returns Nothing, the element is discarded (proper set difference). If
it returns (), the element is updated with a new value Just yy.
let f k al ar = if al == "b" then Just ((show k) ++ ":" ++ al ++ "|" ++ ar) else Nothing
differenceWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (10, "C")])
== singleton 3 "3:b|B"differenceWith :: Ord k => (a -> b -> Maybe a) -> Map k a -> Map k b -> Map k a #
O(n+m). Difference with a combining function.
When two equal keys are
encountered, the combining function is applied to the values of these keys.
If it returns Nothing, the element is discarded (proper set difference). If
it returns (), the element is updated with a new value Just yy.
let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing
differenceWith f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (7, "C")])
== singleton 3 "b:B"unionWithKey :: Ord k => (k -> a -> a -> a) -> Map k a -> Map k a -> Map k a #
O(m*log(n/m + 1)), m <= n. Union with a combining function.
let f key left_value right_value = (show key) ++ ":" ++ left_value ++ "|" ++ right_value unionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "5:a|A"), (7, "C")]
unionWith :: Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a #
O(m*log(n/m + 1)), m <= n. Union with a combining function.
unionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "aA"), (7, "C")]
unionsWith :: Ord k => (a -> a -> a) -> [Map k a] -> Map k a #
The union of a list of maps, with a combining operation:
().unionsWith f == foldl (unionWith f) empty
unionsWith (++) [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])]
== fromList [(3, "bB3"), (5, "aAA3"), (7, "C")]updateMaxWithKey :: (k -> a -> Maybe a) -> Map k a -> Map k a #
O(log n). Update the value at the maximal key.
updateMaxWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"b"), (5,"5:a")] updateMaxWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
updateMinWithKey :: (k -> a -> Maybe a) -> Map k a -> Map k a #
O(log n). Update the value at the minimal key.
updateMinWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"3:b"), (5,"a")] updateMinWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
updateMax :: (a -> Maybe a) -> Map k a -> Map k a #
O(log n). Update the value at the maximal key.
updateMax (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "Xa")]
updateMax (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"updateMin :: (a -> Maybe a) -> Map k a -> Map k a #
O(log n). Update the value at the minimal key.
updateMin (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "Xb"), (5, "a")]
updateMin (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"updateAt :: (k -> a -> Maybe a) -> Int -> Map k a -> Map k a #
O(log n). Update the element at index. Calls error when an
invalid index is used.
updateAt (\ _ _ -> Just "x") 0 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")] updateAt (\ _ _ -> Just "x") 1 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")] updateAt (\ _ _ -> Just "x") 2 (fromList [(5,"a"), (3,"b")]) Error: index out of range updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")]) Error: index out of range updateAt (\_ _ -> Nothing) 0 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" updateAt (\_ _ -> Nothing) 1 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" updateAt (\_ _ -> Nothing) 2 (fromList [(5,"a"), (3,"b")]) Error: index out of range updateAt (\_ _ -> Nothing) (-1) (fromList [(5,"a"), (3,"b")]) Error: index out of range
alterF :: (Functor f, Ord k) => (Maybe a -> f (Maybe a)) -> k -> Map k a -> f (Map k a) #
O(log n). The expression () alters the value alterF f k mapx at k, or absence thereof.
alterF can be used to inspect, insert, delete, or update a value in a Map.
In short: .lookup k <$> alterF f k m = f (lookup k m)
Example:
interactiveAlter :: Int -> Map Int String -> IO (Map Int String)
interactiveAlter k m = alterF f k m where
f Nothing -> do
putStrLn $ show k ++
" was not found in the map. Would you like to add it?"
getUserResponse1 :: IO (Maybe String)
f (Just old) -> do
putStrLn "The key is currently bound to " ++ show old ++
". Would you like to change or delete it?"
getUserresponse2 :: IO (Maybe String)
alterF is the most general operation for working with an individual
key that may or may not be in a given map. When used with trivial
functors like Identity and Const, it is often slightly slower than
more specialized combinators like lookup and insert. However, when
the functor is non-trivial and key comparison is not particularly cheap,
it is the fastest way.
Note on rewrite rules:
This module includes GHC rewrite rules to optimize alterF for
the Const and Identity functors. In general, these rules
improve performance. The sole exception is that when using
Identity, deleting a key that is already absent takes longer
than it would without the rules. If you expect this to occur
a very large fraction of the time, you might consider using a
private copy of the Identity type.
Note: alterF is a flipped version of the at combinator from
At.
alter :: Ord k => (Maybe a -> Maybe a) -> k -> Map k a -> Map k a #
O(log n). The expression () alters the value alter f k mapx at k, or absence thereof.
alter can be used to insert, delete, or update a value in a Map.
In short : .lookup k (alter f k m) = f (lookup k m)
let f _ = Nothing alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] alter f 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" let f _ = Just "c" alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "c")] alter f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "c")]
updateLookupWithKey :: Ord k => (k -> a -> Maybe a) -> k -> Map k a -> (Maybe a, Map k a) #
O(log n). Lookup and update. See also updateWithKey.
The function returns changed value, if it is updated.
Returns the original key value if the map entry is deleted.
let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "5:new a", fromList [(3, "b"), (5, "5:new a")]) updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a")]) updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a")
updateWithKey :: Ord k => (k -> a -> Maybe a) -> k -> Map k a -> Map k a #
O(log n). The expression () updates the
value updateWithKey f k mapx at k (if it is in the map). If (f k x) is Nothing,
the element is deleted. If it is (), the key Just yk is bound
to the new value y.
let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
update :: Ord k => (a -> Maybe a) -> k -> Map k a -> Map k a #
O(log n). The expression () updates the value update f k mapx
at k (if it is in the map). If (f x) is Nothing, the element is
deleted. If it is (), the key Just yk is bound to the new value y.
let f x = if x == "a" then Just "new a" else Nothing update f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] update f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] update f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
adjustWithKey :: Ord k => (k -> a -> a) -> k -> Map k a -> Map k a #
O(log n). Adjust a value at a specific key. When the key is not a member of the map, the original map is returned.
let f key x = (show key) ++ ":new " ++ x adjustWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] adjustWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] adjustWithKey f 7 empty == empty
adjust :: Ord k => (a -> a) -> k -> Map k a -> Map k a #
O(log n). Update a value at a specific key with the result of the provided function. When the key is not a member of the map, the original map is returned.
adjust ("new " ++) 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")]
adjust ("new " ++) 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
adjust ("new " ++) 7 empty == emptyinsertLookupWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> (Maybe a, Map k a) #
O(log n). Combines insert operation with old value retrieval.
The expression ()
is a pair where the first element is equal to (insertLookupWithKey f k x map)
and the second element equal to (lookup k map).insertWithKey f k x map
let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")]) insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "xxx")]) insertLookupWithKey f 5 "xxx" empty == (Nothing, singleton 5 "xxx")
This is how to define insertLookup using insertLookupWithKey:
let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")]) insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "x")])
insertWithKey :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a #
O(log n). Insert with a function, combining key, new value and old value.
will insert the pair (key, value) into insertWithKey f key value mpmp if key does
not exist in the map. If the key does exist, the function will
insert the pair (key,f key new_value old_value).
Note that the key passed to f is the same key passed to insertWithKey.
let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")] insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] insertWithKey f 5 "xxx" empty == singleton 5 "xxx"
insertWith :: Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a #
O(log n). Insert with a function, combining new value and old value.
will insert the pair (key, value) into insertWith f key value mpmp if key does
not exist in the map. If the key does exist, the function will
insert the pair (key, f new_value old_value).
insertWith (++) 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "xxxa")] insertWith (++) 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] insertWith (++) 5 "xxx" empty == singleton 5 "xxx"
insert :: Ord k => k -> a -> Map k a -> Map k a #
O(log n). Insert a new key and value in the map.
If the key is already present in the map, the associated value is
replaced with the supplied value. insert is equivalent to
.insertWith const
insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')] insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')] insert 5 'x' empty == singleton 5 'x'
singleton :: k -> a -> Map k a #
O(1). A map with a single element.
singleton 1 'a' == fromList [(1, 'a')] size (singleton 1 'a') == 1
findWithDefault :: Ord k => a -> k -> Map k a -> a #
O(log n). The expression ( returns
the value at key findWithDefault def k map)k or returns default value def
when the key is not in the map.
findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x' findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a'
showTreeWith :: (k -> a -> String) -> Bool -> Bool -> Map k a -> String #
O(n). The expression () shows
the tree that implements the map. Elements are shown using the showTreeWith showelem hang wide mapshowElem function. If hang is
True, a hanging tree is shown otherwise a rotated tree is shown. If
wide is True, an extra wide version is shown.
Map> let t = fromDistinctAscList [(x,()) | x <- [1..5]]
Map> putStrLn $ showTreeWith (\k x -> show (k,x)) True False t
(4,())
+--(2,())
| +--(1,())
| +--(3,())
+--(5,())
Map> putStrLn $ showTreeWith (\k x -> show (k,x)) True True t
(4,())
|
+--(2,())
| |
| +--(1,())
| |
| +--(3,())
|
+--(5,())
Map> putStrLn $ showTreeWith (\k x -> show (k,x)) False True t
+--(5,())
|
(4,())
|
| +--(3,())
| |
+--(2,())
|
+--(1,())showTree :: (Show k, Show a) => Map k a -> String #
O(n). Show the tree that implements the map. The tree is shown
in a compressed, hanging format. See showTreeWith.
valid :: Ord k => Map k a -> Bool #
O(n). Test if the internal map structure is valid.
valid (fromAscList [(3,"b"), (5,"a")]) == True valid (fromAscList [(5,"a"), (3,"b")]) == False
splitRoot :: Map k b -> [Map k b] #
O(1). Decompose a map into pieces based on the structure of the underlying tree. This function is useful for consuming a map in parallel.
No guarantee is made as to the sizes of the pieces; an internal, but deterministic process determines this. However, it is guaranteed that the pieces returned will be in ascending order (all elements in the first submap less than all elements in the second, and so on).
Examples:
splitRoot (fromList (zip [1..6] ['a'..])) == [fromList [(1,'a'),(2,'b'),(3,'c')],fromList [(4,'d')],fromList [(5,'e'),(6,'f')]]
splitRoot empty == []
Note that the current implementation does not return more than three submaps, but you should not depend on this behaviour because it can change in the future without notice.
Since: containers-0.5.4
deleteFindMax :: Map k a -> ((k, a), Map k a) #
O(log n). Delete and find the maximal element.
deleteFindMax (fromList [(5,"a"), (3,"b"), (10,"c")]) == ((10,"c"), fromList [(3,"b"), (5,"a")]) deleteFindMax empty Error: can not return the maximal element of an empty map
deleteFindMin :: Map k a -> ((k, a), Map k a) #
O(log n). Delete and find the minimal element.
deleteFindMin (fromList [(5,"a"), (3,"b"), (10,"c")]) == ((3,"b"), fromList[(5,"a"), (10,"c")]) deleteFindMin Error: can not return the minimal element of an empty map
splitLookup :: Ord k => k -> Map k a -> (Map k a, Maybe a, Map k a) #
O(log n). The expression () splits a map just
like splitLookup k mapsplit but also returns .lookup k map
splitLookup 2 (fromList [(5,"a"), (3,"b")]) == (empty, Nothing, fromList [(3,"b"), (5,"a")]) splitLookup 3 (fromList [(5,"a"), (3,"b")]) == (empty, Just "b", singleton 5 "a") splitLookup 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Nothing, singleton 5 "a") splitLookup 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Just "a", empty) splitLookup 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], Nothing, empty)
split :: Ord k => k -> Map k a -> (Map k a, Map k a) #
O(log n). The expression () is a pair split k map(map1,map2) where
the keys in map1 are smaller than k and the keys in map2 larger than k.
Any key equal to k is found in neither map1 nor map2.
split 2 (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3,"b"), (5,"a")]) split 3 (fromList [(5,"a"), (3,"b")]) == (empty, singleton 5 "a") split 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a") split 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", empty) split 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], empty)
toDescList :: Map k a -> [(k, a)] #
O(n). Convert the map to a list of key/value pairs where the keys are in descending order. Subject to list fusion.
toDescList (fromList [(5,"a"), (3,"b")]) == [(5,"a"), (3,"b")]
toAscList :: Map k a -> [(k, a)] #
O(n). Convert the map to a list of key/value pairs where the keys are in ascending order. Subject to list fusion.
toAscList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
toList :: Map k a -> [(k, a)] #
O(n). Convert the map to a list of key/value pairs. Subject to list fusion.
toList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")] toList empty == []
O(n). The set of all keys of the map.
keysSet (fromList [(5,"a"), (3,"b")]) == Data.Set.fromList [3,5] keysSet empty == Data.Set.empty
assocs :: Map k a -> [(k, a)] #
O(n). An alias for toAscList. Return all key/value pairs in the map
in ascending key order. Subject to list fusion.
assocs (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")] assocs empty == []
O(n). Return all keys of the map in ascending order. Subject to list fusion.
keys (fromList [(5,"a"), (3,"b")]) == [3,5] keys empty == []
O(n). Return all elements of the map in the ascending order of their keys. Subject to list fusion.
elems (fromList [(5,"a"), (3,"b")]) == ["b","a"] elems empty == []
foldMapWithKey :: Monoid m => (k -> a -> m) -> Map k a -> m #
O(n). Fold the keys and values in the map using the given monoid, such that
foldMapWithKeyf =fold.mapWithKeyf
This can be an asymptotically faster than foldrWithKey or foldlWithKey for some monoids.
Since: containers-0.5.4
foldlWithKey' :: (a -> k -> b -> a) -> a -> Map k b -> a #
O(n). A strict version of foldlWithKey. Each application of the operator is
evaluated before using the result in the next application. This
function is strict in the starting value.
foldlWithKey :: (a -> k -> b -> a) -> a -> Map k b -> a #
O(n). Fold the keys and values in the map using the given left-associative
binary operator, such that
.foldlWithKey f z == foldl (\z' (kx, x) -> f z' kx x) z . toAscList
For example,
keys = reverse . foldlWithKey (\ks k x -> k:ks) []
let f result k a = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
foldlWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (3:b)(5:a)"foldrWithKey' :: (k -> a -> b -> b) -> b -> Map k a -> b #
O(n). A strict version of foldrWithKey. Each application of the operator is
evaluated before using the result in the next application. This
function is strict in the starting value.
foldrWithKey :: (k -> a -> b -> b) -> b -> Map k a -> b #
O(n). Fold the keys and values in the map using the given right-associative
binary operator, such that
.foldrWithKey f z == foldr (uncurry f) z . toAscList
For example,
keys map = foldrWithKey (\k x ks -> k:ks) [] map
let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
foldrWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)"foldl' :: (a -> b -> a) -> a -> Map k b -> a #
O(n). A strict version of foldl. Each application of the operator is
evaluated before using the result in the next application. This
function is strict in the starting value.
foldr' :: (a -> b -> b) -> b -> Map k a -> b #
O(n). A strict version of foldr. Each application of the operator is
evaluated before using the result in the next application. This
function is strict in the starting value.
mapKeysMonotonic :: (k1 -> k2) -> Map k1 a -> Map k2 a #
O(n).
, but works only when mapKeysMonotonic f s == mapKeys f sf
is strictly monotonic.
That is, for any values x and y, if x < y then f x < f y.
The precondition is not checked.
Semi-formally, we have:
and [x < y ==> f x < f y | x <- ls, y <- ls]
==> mapKeysMonotonic f s == mapKeys f s
where ls = keys sThis means that f maps distinct original keys to distinct resulting keys.
This function has better performance than mapKeys.
mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")]) == fromList [(6, "b"), (10, "a")] valid (mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")])) == True valid (mapKeysMonotonic (\ _ -> 1) (fromList [(5,"a"), (3,"b")])) == False
mapKeys :: Ord k2 => (k1 -> k2) -> Map k1 a -> Map k2 a #
O(n*log n).
is the map obtained by applying mapKeys f sf to each key of s.
The size of the result may be smaller if f maps two or more distinct
keys to the same new key. In this case the value at the greatest of the
original keys is retained.
mapKeys (+ 1) (fromList [(5,"a"), (3,"b")]) == fromList [(4, "b"), (6, "a")] mapKeys (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "c" mapKeys (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "c"
partitionWithKey :: (k -> a -> Bool) -> Map k a -> (Map k a, Map k a) #
O(n). Partition the map according to a predicate. The first
map contains all elements that satisfy the predicate, the second all
elements that fail the predicate. See also split.
partitionWithKey (\ k _ -> k > 3) (fromList [(5,"a"), (3,"b")]) == (singleton 5 "a", singleton 3 "b") partitionWithKey (\ k _ -> k < 7) (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty) partitionWithKey (\ k _ -> k > 7) (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")])
partition :: (a -> Bool) -> Map k a -> (Map k a, Map k a) #
O(n). Partition the map according to a predicate. The first
map contains all elements that satisfy the predicate, the second all
elements that fail the predicate. See also split.
partition (> "a") (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a") partition (< "x") (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty) partition (> "x") (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")])
spanAntitone :: (k -> Bool) -> Map k a -> (Map k a, Map k a) #
O(log n). Divide a map at the point where a predicate on the keys stops holding.
The user is responsible for ensuring that for all keys j and k in the map,
j < k ==> p j >= p k.
spanAntitone p xs = (takeWhileAntitonep xs,dropWhileAntitonep xs) spanAntitone p xs = partition p xs
Note: if p is not actually antitone, then spanAntitone will split the map
at some unspecified point where the predicate switches from holding to not
holding (where the predicate is seen to hold before the first key and to fail
after the last key).
Since: containers-0.5.8
dropWhileAntitone :: (k -> Bool) -> Map k a -> Map k a #
O(log n). Drop while a predicate on the keys holds.
The user is responsible for ensuring that for all keys j and k in the map,
j < k ==> p j >= p k. See note at spanAntitone.
dropWhileAntitone p =fromDistinctAscList.dropWhile(p . fst) .toListdropWhileAntitone p =filterWithKey(k -> not (p k))
Since: containers-0.5.8
takeWhileAntitone :: (k -> Bool) -> Map k a -> Map k a #
O(log n). Take while a predicate on the keys holds.
The user is responsible for ensuring that for all keys j and k in the map,
j < k ==> p j >= p k. See note at spanAntitone.
takeWhileAntitone p =fromDistinctAscList.takeWhile(p . fst) .toListtakeWhileAntitone p =filterWithKey(k _ -> p k)
Since: containers-0.5.8
filterWithKey :: (k -> a -> Bool) -> Map k a -> Map k a #
O(n). Filter all keys/values that satisfy the predicate.
filterWithKey (\k _ -> k > 4) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
filter :: (a -> Bool) -> Map k a -> Map k a #
O(n). Filter all values that satisfy the predicate.
filter (> "a") (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" filter (> "x") (fromList [(5,"a"), (3,"b")]) == empty filter (< "a") (fromList [(5,"a"), (3,"b")]) == empty
isProperSubmapOfBy :: Ord k => (a -> b -> Bool) -> Map k a -> Map k b -> Bool #
O(m*log(n/m + 1)), m <= n. Is this a proper submap? (ie. a submap but not equal).
The expression () returns isProperSubmapOfBy f m1 m2True when
m1 and m2 are not equal,
all keys in m1 are in m2, and when f returns True when
applied to their respective values. For example, the following
expressions are all True:
isProperSubmapOfBy (==) (fromList [(1,1)]) (fromList [(1,1),(2,2)]) isProperSubmapOfBy (<=) (fromList [(1,1)]) (fromList [(1,1),(2,2)])
But the following are all False:
isProperSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1),(2,2)]) isProperSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1)]) isProperSubmapOfBy (<) (fromList [(1,1)]) (fromList [(1,1),(2,2)])
isProperSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> Bool #
O(m*log(n/m + 1)), m <= n. Is this a proper submap? (ie. a submap but not equal).
Defined as ().isProperSubmapOf = isProperSubmapOfBy (==)
isSubmapOfBy :: Ord k => (a -> b -> Bool) -> Map k a -> Map k b -> Bool #
O(m*log(n/m + 1)), m <= n.
The expression () returns isSubmapOfBy f t1 t2True if
all keys in t1 are in tree t2, and when f returns True when
applied to their respective values. For example, the following
expressions are all True:
isSubmapOfBy (==) (fromList [('a',1)]) (fromList [('a',1),('b',2)])
isSubmapOfBy (<=) (fromList [('a',1)]) (fromList [('a',1),('b',2)])
isSubmapOfBy (==) (fromList [('a',1),('b',2)]) (fromList [('a',1),('b',2)])But the following are all False:
isSubmapOfBy (==) (fromList [('a',2)]) (fromList [('a',1),('b',2)])
isSubmapOfBy (<) (fromList [('a',1)]) (fromList [('a',1),('b',2)])
isSubmapOfBy (==) (fromList [('a',1),('b',2)]) (fromList [('a',1)])isSubmapOf :: (Ord k, Eq a) => Map k a -> Map k a -> Bool #
O(m*log(n/m + 1)), m <= n.
This function is defined as ().isSubmapOf = isSubmapOfBy (==)
restrictKeys :: Ord k => Map k a -> Set k -> Map k a #
O(m*log(n/m + 1)), m <= n. Restrict a Map to only those keys
found in a Set.
m `restrictKeys's =filterWithKey(k _ -> k `member's) m m `restrictKeys's = m `intersectfromSet(const ()) s
Since: containers-0.5.8
intersection :: Ord k => Map k a -> Map k b -> Map k a #
O(m*log(n/m + 1)), m <= n. Intersection of two maps.
Return data in the first map for the keys existing in both maps.
().intersection m1 m2 == intersectionWith const m1 m2
intersection (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "a"
withoutKeys :: Ord k => Map k a -> Set k -> Map k a #
O(m*log(n/m + 1)), m <= n. Remove all keys in a Set from a Map.
m `withoutKeys's =filterWithKey(k _ -> k `notMember's) m m `withoutKeys's = m `difference'fromSet(const ()) s
Since: containers-0.5.8
difference :: Ord k => Map k a -> Map k b -> Map k a #
O(m*log(n/m + 1)), m <= n. Difference of two maps. Return elements of the first map not existing in the second map.
difference (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 3 "b"
unions :: Ord k => [Map k a] -> Map k a #
The union of a list of maps:
().unions == foldl union empty
unions [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])]
== fromList [(3, "b"), (5, "a"), (7, "C")]
unions [(fromList [(5, "A3"), (3, "B3")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "a"), (3, "b")])]
== fromList [(3, "B3"), (5, "A3"), (7, "C")]maxView :: Map k a -> Maybe (a, Map k a) #
O(log n). Retrieves the value associated with maximal key of the
map, and the map stripped of that element, or Nothing if passed an
empty map.
maxView (fromList [(5,"a"), (3,"b")]) == Just ("a", singleton 3 "b")
maxView empty == NothingminView :: Map k a -> Maybe (a, Map k a) #
O(log n). Retrieves the value associated with minimal key of the
map, and the map stripped of that element, or Nothing if passed an
empty map.
minView (fromList [(5,"a"), (3,"b")]) == Just ("b", singleton 5 "a")
minView empty == NothingmaxViewWithKey :: Map k a -> Maybe ((k, a), Map k a) #
O(log n). Retrieves the maximal (key,value) pair of the map, and
the map stripped of that element, or Nothing if passed an empty map.
maxViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((5,"a"), singleton 3 "b") maxViewWithKey empty == Nothing
minViewWithKey :: Map k a -> Maybe ((k, a), Map k a) #
O(log n). Retrieves the minimal (key,value) pair of the map, and
the map stripped of that element, or Nothing if passed an empty map.
minViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((3,"b"), singleton 5 "a") minViewWithKey empty == Nothing
deleteMax :: Map k a -> Map k a #
O(log n). Delete the maximal key. Returns an empty map if the map is empty.
deleteMax (fromList [(5,"a"), (3,"b"), (7,"c")]) == fromList [(3,"b"), (5,"a")] deleteMax empty == empty
deleteMin :: Map k a -> Map k a #
O(log n). Delete the minimal key. Returns an empty map if the map is empty.
deleteMin (fromList [(5,"a"), (3,"b"), (7,"c")]) == fromList [(5,"a"), (7,"c")] deleteMin empty == empty
lookupMax :: Map k a -> Maybe (k, a) #
O(log n). The maximal key of the map. Returns Nothing if the map is empty.
lookupMax (fromList [(5,"a"), (3,"b")]) == Just (5,"a") lookupMax empty = Nothing
Since: containers-0.5.9
findMin :: Map k a -> (k, a) #
O(log n). The minimal key of the map. Calls error if the map is empty.
findMin (fromList [(5,"a"), (3,"b")]) == (3,"b") findMin empty Error: empty map has no minimal element
lookupMin :: Map k a -> Maybe (k, a) #
O(log n). The minimal key of the map. Returns Nothing if the map is empty.
lookupMin (fromList [(5,"a"), (3,"b")]) == Just (3,"b") findMin empty = Nothing
Since: containers-0.5.9
deleteAt :: Int -> Map k a -> Map k a #
O(log n). Delete the element at index, i.e. by its zero-based index in
the sequence sorted by keys. If the index is out of range (less than zero,
greater or equal to size of the map), error is called.
deleteAt 0 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" deleteAt 1 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" deleteAt 2 (fromList [(5,"a"), (3,"b")]) Error: index out of range deleteAt (-1) (fromList [(5,"a"), (3,"b")]) Error: index out of range
drop :: Int -> Map k a -> Map k a #
Drop a given number of entries in key order, beginning with the smallest keys.
drop n =fromDistinctAscList.dropn .toAscList
Since: containers-0.5.8
take :: Int -> Map k a -> Map k a #
Take a given number of entries in key order, beginning with the smallest keys.
take n =fromDistinctAscList.taken .toAscList
Since: containers-0.5.8
elemAt :: Int -> Map k a -> (k, a) #
O(log n). Retrieve an element by its index, i.e. by its zero-based
index in the sequence sorted by keys. If the index is out of range (less
than zero, greater or equal to size of the map), error is called.
elemAt 0 (fromList [(5,"a"), (3,"b")]) == (3,"b") elemAt 1 (fromList [(5,"a"), (3,"b")]) == (5, "a") elemAt 2 (fromList [(5,"a"), (3,"b")]) Error: index out of range
lookupIndex :: Ord k => k -> Map k a -> Maybe Int #
O(log n). Lookup the index of a key, which is its zero-based index in
the sequence sorted by keys. The index is a number from 0 up to, but not
including, the size of the map.
isJust (lookupIndex 2 (fromList [(5,"a"), (3,"b")])) == False fromJust (lookupIndex 3 (fromList [(5,"a"), (3,"b")])) == 0 fromJust (lookupIndex 5 (fromList [(5,"a"), (3,"b")])) == 1 isJust (lookupIndex 6 (fromList [(5,"a"), (3,"b")])) == False
findIndex :: Ord k => k -> Map k a -> Int #
O(log n). Return the index of a key, which is its zero-based index in
the sequence sorted by keys. The index is a number from 0 up to, but not
including, the size of the map. Calls error when the key is not
a member of the map.
findIndex 2 (fromList [(5,"a"), (3,"b")]) Error: element is not in the map findIndex 3 (fromList [(5,"a"), (3,"b")]) == 0 findIndex 5 (fromList [(5,"a"), (3,"b")]) == 1 findIndex 6 (fromList [(5,"a"), (3,"b")]) Error: element is not in the map
delete :: Ord k => k -> Map k a -> Map k a #
O(log n). Delete a key and its value from the map. When the key is not a member of the map, the original map is returned.
delete 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" delete 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] delete 5 empty == empty
lookupGE :: Ord k => k -> Map k v -> Maybe (k, v) #
O(log n). Find smallest key greater or equal to the given one and return the corresponding (key, value) pair.
lookupGE 3 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') lookupGE 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') lookupGE 6 (fromList [(3,'a'), (5,'b')]) == Nothing
lookupLE :: Ord k => k -> Map k v -> Maybe (k, v) #
O(log n). Find largest key smaller or equal to the given one and return the corresponding (key, value) pair.
lookupLE 2 (fromList [(3,'a'), (5,'b')]) == Nothing lookupLE 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') lookupLE 5 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b')
lookupGT :: Ord k => k -> Map k v -> Maybe (k, v) #
O(log n). Find smallest key greater than the given one and return the corresponding (key, value) pair.
lookupGT 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') lookupGT 5 (fromList [(3,'a'), (5,'b')]) == Nothing
lookupLT :: Ord k => k -> Map k v -> Maybe (k, v) #
O(log n). Find largest key smaller than the given one and return the corresponding (key, value) pair.
lookupLT 3 (fromList [(3,'a'), (5,'b')]) == Nothing lookupLT 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a')
notMember :: Ord k => k -> Map k a -> Bool #
O(log n). Is the key not a member of the map? See also member.
notMember 5 (fromList [(5,'a'), (3,'b')]) == False notMember 1 (fromList [(5,'a'), (3,'b')]) == True
member :: Ord k => k -> Map k a -> Bool #
O(log n). Is the key a member of the map? See also notMember.
member 5 (fromList [(5,'a'), (3,'b')]) == True member 1 (fromList [(5,'a'), (3,'b')]) == False
lookup :: Ord k => k -> Map k a -> Maybe a #
O(log n). Lookup the value at a key in the map.
The function will return the corresponding value as (,
or Just value)Nothing if the key isn't in the map.
An example of using lookup:
import Prelude hiding (lookup)
import Data.Map
employeeDept = fromList([("John","Sales"), ("Bob","IT")])
deptCountry = fromList([("IT","USA"), ("Sales","France")])
countryCurrency = fromList([("USA", "Dollar"), ("France", "Euro")])
employeeCurrency :: String -> Maybe String
employeeCurrency name = do
dept <- lookup name employeeDept
country <- lookup dept deptCountry
lookup country countryCurrency
main = do
putStrLn $ "John's currency: " ++ (show (employeeCurrency "John"))
putStrLn $ "Pete's currency: " ++ (show (employeeCurrency "Pete"))The output of this program:
John's currency: Just "Euro" Pete's currency: Nothing
O(1). The number of elements in the map.
size empty == 0 size (singleton 1 'a') == 1 size (fromList([(1,'a'), (2,'c'), (3,'b')])) == 3
O(1). Is the map empty?
Data.Map.null (empty) == True Data.Map.null (singleton 1 'a') == False
(!?) :: Ord k => Map k a -> k -> Maybe a infixl 9 #
O(log n). Find the value at a key.
Returns Nothing when the element can not be found.
fromList [(5, 'a'), (3, 'b')] !? 1 == Nothing
fromList [(5, 'a'), (3, 'b')] !? 5 == Just 'a'
Since: containers-0.5.9
(!) :: Ord k => Map k a -> k -> a infixl 9 #
O(log n). Find the value at a key.
Calls error when the element can not be found.
fromList [(5,'a'), (3,'b')] ! 1 Error: element not in the map fromList [(5,'a'), (3,'b')] ! 5 == 'a'
We need to wrap Doubles for the same reason we need to wrap Ints.
Class used to create a Ref from another type.
Minimal complete definition
We need to wrap Bools for the same reason we need to wrap Ints.
We need to wrap integers so we can override the Aeson type-classes. This is necessary because CloudFront made the silly decision to represent numbers as JSON strings.
Constructors
| Integer' | |
Fields | |
ValList is like Val, except it is used in place of lists of Vals in
templates. For example, if you have a parameter called SubnetIds of type
ListAWS::EC2::Subnet::Id then, you can use RefList SubnetIds to
reference it.
This type is a wrapper around any values in a template. A value can be a
Literal, a Ref, or an intrinsic function. See:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
Constructors
| Literal a | |
| Ref Text | |
| If Text (Val a) (Val a) | |
| And (Val Bool) (Val Bool) | |
| Equals (Val a) (Val a) | |
| Or (Val Bool) (Val Bool) | |
| GetAtt Text Text | |
| Base64 (Val Text) | |
| Join Text (ValList Text) | |
| Select Integer (ValList a) | |
| FindInMap (Val a) (Val a) (Val a) | Map name, top level key, and second level key |
| ImportValue Text | The account-and-region-unique exported name of the value to import |
| Sub Text (Maybe (HashMap Text (Val Text))) | Substitution string and optional map of values |