data-object-0.3.1.6: Represent hierachichal structures, called objects in JSON.

Data.Object

Contents

Description

The core of this package is the Object data type, which is used for handling scalars, sequences and mappings in a nested manner. This is the same structure used in JSON or Yaml data.

The Object data type is polymorphic in its keys and values. Submodules within this package provide more concrete datatypes, such as a String Object and a specialized scalar type.

Besides the Object data type, there are utility functions and type classes for converting objects around. Care has been taken to avoid any overloaded instances for these type classes.

Synopsis

Object data type

data Object key val Source

Can represent nested values as scalars, sequences and mappings. A sequence is synonymous with a list, while a mapping is synonymous with a list of pairs.

Note that instances of standard library type classes for this data type leave the key untouched while altering the value. For example, the Functor instance defines fmap to be synonymous with mapValues.

Constructors

Mapping [(key, Object key val)] 
Sequence [Object key val] 
Scalar val 

Instances

Typeable2 Object 
Monad (Object key) 
Functor (Object key) 
Applicative (Object key) 
Foldable (Object key) 
Traversable (Object key) 
(Eq key, Eq val) => Eq (Object key val) 
(Data key, Data val) => Data (Object key val) 
(Show key, Show val) => Show (Object key val) 

Convenient type synonyms

type TextObject = Object Text TextSource

Objects with keys and values of strict Text.

Scalar data type

Basic mapping of keys and values

mapKeys :: (keyIn -> keyOut) -> Object keyIn val -> Object keyOut valSource

Apply some conversion to the keys of an Object, leaving the values unchanged.

mapValues :: (valIn -> valOut) -> Object key valIn -> Object key valOutSource

Apply some conversion to the values of an Object, leaving the keys unchanged. This is equivalent to fmap.

mapKeysValues :: (keyIn -> keyOut) -> (valIn -> valOut) -> Object keyIn valIn -> Object keyOut valOutSource

Apply a conversion to both the keys and values of an Object.

mapKeysValuesA :: Applicative f => (keyIn -> f keyOut) -> (valIn -> f valOut) -> Object keyIn valIn -> f (Object keyOut valOut)Source

Apply an Applicative conversion to both the keys and values of an Object.

mapKeysValuesM :: Monad m => (keyIn -> m keyOut) -> (valIn -> m valOut) -> Object keyIn valIn -> m (Object keyOut valOut)Source

The same as mapKeysValuesA, but using a Monad since some people are more comfortable with Monads and not all Monads are Applicative.

Extracting underlying values

data ObjectExtractError Source

An error value returned when an unexpected node is encountered, eg you were expecting a Scalar and found a Mapping.

fromScalar :: Failure ObjectExtractError m => Object k v -> m vSource

Extract a scalar from the input, failing if the input is a sequence or mapping.

fromSequence :: Failure ObjectExtractError m => Object k v -> m [Object k v]Source

Extract a sequence from the input, failing if the input is a scalar or mapping.

fromMapping :: Failure ObjectExtractError m => Object k v -> m [(k, Object k v)]Source

Extract a mapping from the input, failing if the input is a scalar or sequence.

Lookups

lookupObject :: (Show k, Eq k, Failure ObjectExtractError m) => k -> [(k, Object k v)] -> m (Object k v)Source

lookupScalar :: (Show k, Eq k, Failure ObjectExtractError m) => k -> [(k, Object k v)] -> m vSource

lookupSequence :: (Show k, Eq k, Failure ObjectExtractError m) => k -> [(k, Object k v)] -> m [Object k v]Source

lookupMapping :: (Show k, Eq k, Failure ObjectExtractError m) => k -> [(k, Object k v)] -> m [(k, Object k v)]Source