Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data structures and functions for handling the elements contained in a CommaSeparated
structure.
Synopsis
- data Elems ws a = Elems {
- _elemsElems :: Vector (Elem Identity ws a)
- _elemsLast :: Elem Maybe ws a
- class HasElems c ws a | c -> ws a where
- parseCommaSeparatedElems :: (Monad f, CharParsing f) => f ws -> f a -> f (Elems ws a)
- consElems :: Monoid ws => ((Comma, ws), a) -> Elems ws a -> Elems ws a
- unconsElems :: Monoid ws => Elems ws a -> ((Maybe (Comma, ws), a), Maybe (Elems ws a))
Types
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.
Elems | |
|
Instances
Bifunctor Elems Source # | |
Bitraversable Elems Source # | |
Defined in Waargonaut.Types.CommaSep.Elems bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Elems a b -> f (Elems c d) # | |
Bifoldable Elems Source # | |
Functor (Elems ws) Source # | |
Monoid ws => Applicative (Elems ws) Source # | |
Foldable (Elems ws) Source # | |
Defined in Waargonaut.Types.CommaSep.Elems fold :: Monoid m => Elems ws m -> 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 # elem :: Eq a => a -> Elems ws a -> Bool # maximum :: Ord a => Elems ws a -> a # minimum :: Ord a => Elems ws a -> a # | |
Traversable (Elems ws) Source # | |
Defined in Waargonaut.Types.CommaSep.Elems | |
(Eq ws, Eq a) => Eq (Elems ws a) Source # | |
(Show ws, Show a) => Show (Elems ws a) Source # | |
Monoid ws => Semigroup (Elems ws a) Source # | |
HasElems (Elems ws a) ws a Source # | |
class HasElems c ws a | c -> ws a where Source #
Typeclass for things that contain an Elems
structure.
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])}})