gather-0.1.0.0: An applicative for parsing unordered things, heterogenous sorting

Data.Gather

Synopsis

# Documentation

data Gather g f a Source #

Fold over the outcomes of a type that has an Alternative.

Gather embodies two steps.

• Getting data using many and <|> from Alternative
• Postprocessing the data in some way.

For example, Gather (Either String) Parser is a type that helps you parse a sequence of mixed production, similar to many (p1 | p2 | p3) but then it also lets you specify what to do with the aggregate result p1 and the aggregate result of p2 and so on.

Example:

data Vehicle = Vehicle { wheels :: [Wheel], seats :: (Seat, [Seat]) }

-- | Parse vehicle parts in any order
parseVehicle = join $runGather ( Vehicle <$> zeroOrMore parseWheel
<*> oneOrMore (fail "A vehicle requires at least one seat.") parseSeat
)

Constructors

 Monoid m => Gather Fieldsitems :: f m postProcess :: m -> g a
Instances
 (Functor g, Functor f) => Functor (Gather g f) Source # Instance detailsDefined in Data.Gather Methodsfmap :: (a -> b) -> Gather g f a -> Gather g f b #(<\$) :: a -> Gather g f b -> Gather g f a # (Applicative g, Alternative f) => Applicative (Gather g f) Source # Instance detailsDefined in Data.Gather Methodspure :: a -> Gather g f a #(<*>) :: Gather g f (a -> b) -> Gather g f a -> Gather g f b #liftA2 :: (a -> b -> c) -> Gather g f a -> Gather g f b -> Gather g f c #(*>) :: Gather g f a -> Gather g f b -> Gather g f b #(<*) :: Gather g f a -> Gather g f b -> Gather g f a #

type Gather' f = Gather f f Source #

Simple type for parsing monads that also take care of error handling or other postProcess concerns.

runGather :: Alternative f => Gather g f a -> f (g a) Source #

runGather' :: (Alternative f, Monad f) => Gather' f a -> f a Source #

join . runGather

gather :: Monoid m => (m -> g a) -> f m -> Gather g f a Source #

zeroOrMore :: (Functor f, Applicative g) => f a -> Gather g f [a] Source #

zeroOrMore_ :: (Functor f, Applicative g) => f a -> Gather g f () Source #

Arguments

 :: (Functor f, Applicative g) => g (Maybe a) on many, typically a fail, Left or similar -> f a -> Gather g f (Maybe a)

Arguments

 :: (Functor f, Applicative g) => g (a, [a]) on zero, typically a fail, Left or similar -> f a -> Gather g f (a, [a])

Arguments

 :: (Functor f, Applicative g) => g a on zero, typically a fail, Left or similar -> g a on many, typically a fail, Left or similar -> f a -> Gather g f a

Naive implementation that does not backtrack after the item has been parsed once. This may change in the future.