waargonaut-0.8.0.2: JSON wrangling
Safe HaskellNone
LanguageHaskell2010

Waargonaut.Types.CommaSep.Elems

Description

Data structures and functions for handling the elements contained in a CommaSeparated structure.

Synopsis

Types

data Elems ws a Source #

This type represents a non-empty list of elements, enforcing that the any element but the last must be followed by a trailing comma and supporting option of a final trailing comma.

Constructors

Elems 

Fields

Instances

Instances details
Bitraversable Elems Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Elems a b -> f (Elems c d) #

Bifoldable Elems Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

bifold :: Monoid m => Elems m m -> m #

bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> Elems a b -> m #

bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> Elems a b -> c #

bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> Elems a b -> c #

Bifunctor Elems Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

bimap :: (a -> b) -> (c -> d) -> Elems a c -> Elems b d #

first :: (a -> b) -> Elems a c -> Elems b c #

second :: (b -> c) -> Elems a b -> Elems a c #

Functor (Elems ws) Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

fmap :: (a -> b) -> Elems ws a -> Elems ws b #

(<$) :: a -> Elems ws b -> Elems ws a #

Monoid ws => Applicative (Elems ws) Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

pure :: a -> Elems ws a #

(<*>) :: Elems ws (a -> b) -> Elems ws a -> Elems ws b #

liftA2 :: (a -> b -> c) -> Elems ws a -> Elems ws b -> Elems ws c #

(*>) :: Elems ws a -> Elems ws b -> Elems ws b #

(<*) :: Elems ws a -> Elems ws b -> Elems ws a #

Foldable (Elems ws) Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

fold :: Monoid m => Elems ws m -> m #

foldMap :: Monoid m => (a -> m) -> Elems ws a -> m #

foldMap' :: Monoid m => (a -> m) -> Elems ws a -> m #

foldr :: (a -> b -> b) -> b -> Elems ws a -> b #

foldr' :: (a -> b -> b) -> b -> Elems ws a -> b #

foldl :: (b -> a -> b) -> b -> Elems ws a -> b #

foldl' :: (b -> a -> b) -> b -> Elems ws a -> b #

foldr1 :: (a -> a -> a) -> Elems ws a -> a #

foldl1 :: (a -> a -> a) -> Elems ws a -> a #

toList :: Elems ws a -> [a] #

null :: Elems ws a -> Bool #

length :: Elems ws a -> Int #

elem :: Eq a => a -> Elems ws a -> Bool #

maximum :: Ord a => Elems ws a -> a #

minimum :: Ord a => Elems ws a -> a #

sum :: Num a => Elems ws a -> a #

product :: Num a => Elems ws a -> a #

Traversable (Elems ws) Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

traverse :: Applicative f => (a -> f b) -> Elems ws a -> f (Elems ws b) #

sequenceA :: Applicative f => Elems ws (f a) -> f (Elems ws a) #

mapM :: Monad m => (a -> m b) -> Elems ws a -> m (Elems ws b) #

sequence :: Monad m => Elems ws (m a) -> m (Elems ws a) #

(Eq ws, Eq a) => Eq (Elems ws a) Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

(==) :: Elems ws a -> Elems ws a -> Bool #

(/=) :: Elems ws a -> Elems ws a -> Bool #

(Show ws, Show a) => Show (Elems ws a) Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

showsPrec :: Int -> Elems ws a -> ShowS #

show :: Elems ws a -> String #

showList :: [Elems ws a] -> ShowS #

Monoid ws => Semigroup (Elems ws a) Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

(<>) :: Elems ws a -> Elems ws a -> Elems ws a #

sconcat :: NonEmpty (Elems ws a) -> Elems ws a #

stimes :: Integral b => b -> Elems ws a -> Elems ws a #

HasElems (Elems ws a) ws a Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

elems :: Lens' (Elems ws a) (Elems ws a) Source #

elemsElems :: Lens' (Elems ws a) (Vector (Elem Identity ws a)) Source #

elemsLast :: Lens' (Elems ws a) (Elem Maybe ws a) Source #

class HasElems c ws a | c -> ws a where Source #

Typeclass for things that contain an Elems structure.

Minimal complete definition

elems

Methods

elems :: Lens' c (Elems ws a) Source #

elemsElems :: Lens' c (Vector (Elem Identity ws a)) Source #

elemsLast :: Lens' c (Elem Maybe ws a) Source #

Instances

Instances details
HasElems (Elems ws a) ws a Source # 
Instance details

Defined in Waargonaut.Types.CommaSep.Elems

Methods

elems :: Lens' (Elems ws a) (Elems ws a) Source #

elemsElems :: Lens' (Elems ws a) (Vector (Elem Identity ws a)) Source #

elemsLast :: Lens' (Elems ws a) (Elem Maybe ws a) Source #

Parse

parseCommaSeparatedElems :: (Monad f, CharParsing f) => f ws -> f a -> f (Elems ws a) Source #

Parse the elements of a CommaSeparated list, handling the optional trailing comma and its whitespace.

>>> testparse (parseCommaSeparatedElems parseWhitespace alphaNum) "a, b, c, d"
Right (Elems {_elemsElems = [Elem {_elemVal = 'a', _elemTrailing = Identity (Comma,WS [Space])},Elem {_elemVal = 'b', _elemTrailing = Identity (Comma,WS [Space])},Elem {_elemVal = 'c', _elemTrailing = Identity (Comma,WS [Space])}], _elemsLast = Elem {_elemVal = 'd', _elemTrailing = Nothing}})
>>> testparse (parseCommaSeparatedElems parseWhitespace alphaNum) "a, b,c,d, "
Right (Elems {_elemsElems = [Elem {_elemVal = 'a', _elemTrailing = Identity (Comma,WS [Space])},Elem {_elemVal = 'b', _elemTrailing = Identity (Comma,WS [])},Elem {_elemVal = 'c', _elemTrailing = Identity (Comma,WS [])}], _elemsLast = Elem {_elemVal = 'd', _elemTrailing = Just (Comma,WS [Space])}})
>>> testparse (parseCommaSeparatedElems parseWhitespace alphaNum) "d, "
Right (Elems {_elemsElems = [], _elemsLast = Elem {_elemVal = 'd', _elemTrailing = Just (Comma,WS [Space])}})
>>> testparse (parseCommaSeparatedElems parseWhitespace charWS) "d , "
Right (Elems {_elemsElems = [], _elemsLast = Elem {_elemVal = ('d',WS [Space]), _elemTrailing = Just (Comma,WS [Space])}})
>>> testparse (parseCommaSeparatedElems parseWhitespace charWS) "d\n, e,  "
Right (Elems {_elemsElems = [Elem {_elemVal = ('d',WS [NewLine]), _elemTrailing = Identity (Comma,WS [Space])}], _elemsLast = Elem {_elemVal = ('e',WS []), _elemTrailing = Just (Comma,WS [Space,Space])}})

Functions

consElems :: Monoid ws => ((Comma, ws), a) -> Elems ws a -> Elems ws a Source #

Add a value to the beginning of the Elems

unconsElems :: Monoid ws => Elems ws a -> ((Maybe (Comma, ws), a), Maybe (Elems ws a)) Source #

Attempt to remove the initial value off the front of an Elems