Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Grab bag residue log desideratum = Grab (bag -> (residue, log, Maybe desideratum))
- type Simple bag log desideratum = Grab bag bag log desideratum
- type Dump bag log desideratum = Grab bag () log desideratum
- type Result residue log desideratum = Grab () residue log desideratum
- type Extract log desideratum = Grab () () log desideratum
- partition :: forall bag residue log desideratum. Monoid log => (bag -> (desideratum, residue)) -> Grab bag residue log desideratum
- (/) :: forall bag residue _r log x desideratum. Semigroup log => Grab bag residue log x -> Grab x _r log desideratum -> Grab bag residue log desideratum
- dump :: forall bag log desideratum. (bag -> Extract log desideratum) -> Dump bag log desideratum
- discardResidue :: forall bag residue log desideratum. Grab bag residue log desideratum -> Dump bag log desideratum
- success :: forall log desideratum. Monoid log => desideratum -> Extract log desideratum
- failure :: forall log desideratum. log -> Extract log desideratum
- warning :: forall log. log -> Extract log ()
- extract :: forall log desideratum. log -> Maybe desideratum -> Extract log desideratum
- runGrab :: forall bag residue log desideratum. Grab bag residue log desideratum -> bag -> Result residue log desideratum
- runDump :: forall bag log desideratum. Dump bag log desideratum -> bag -> Extract log desideratum
- residue :: forall residue log desideratum. Result residue log desideratum -> residue
- log :: forall residue log desideratum. Result residue log desideratum -> log
- desideratum :: forall residue log desideratum. Result residue log desideratum -> Maybe desideratum
- runGrabMaybe :: forall bag residue log desideratum. Grab bag residue log desideratum -> bag -> Maybe desideratum
Types
The Grab type
newtype Grab bag residue log desideratum Source #
A Grab
:
- Consumes some portion (none, part, or all) of its input
bag
; Returns a
Result
:- A
residue
consisting of the unconsumed input; - Some monoidal
log
e.g. a list of error messages; - Some
desideratum
(the object of desire) produced from the consumed input, orNothing
if the grab failed.
- A
Specializations of this type:
- If the bag and residue types are the same, the grab
is a
Simple
grab and it has anApplicative
instance. - If the residue is
()
, the grab is aDump
; it dumps out the entire bag so there is nothing remaining. - If the bag is
()
, the grab is just a single fixedResult
, which consists of the residue, log, and maybe the desideratum. - If both the bag and residue are
()
, the grab is just theExtract
, which consists of the log and maybe the desideratum.
Instances
Bifunctor (Grab bag residue) Source # | |
Functor (Grab bag residue log) Source # | |
(bag ~ residue, Monoid log) => Applicative (Grab bag residue log) Source # | |
Defined in Control.Grab pure :: a -> Grab bag residue log a # (<*>) :: Grab bag residue log (a -> b) -> Grab bag residue log a -> Grab bag residue log b # liftA2 :: (a -> b -> c) -> Grab bag residue log a -> Grab bag residue log b -> Grab bag residue log c # (*>) :: Grab bag residue log a -> Grab bag residue log b -> Grab bag residue log b # (<*) :: Grab bag residue log a -> Grab bag residue log b -> Grab bag residue log a # |
Aliases: Simple, Dump, Result, Extract
type Simple bag log desideratum = Grab bag bag log desideratum Source #
A Simple
grab:
- Consumes some portion (none, part, or all) of its input
bag
; Returns a
Result
:- A modified
bag
representing the unconsumed portion of the input; - Some monoidal
log
e.g. a list of error messages; - Some
desideratum
(the object of desire) produced from the consumed input, orNothing
if the grab failed.
- A modified
type Result residue log desideratum = Grab () residue log desideratum Source #
The result of performing a Grab
. Consists of:
- A
residue
consisting of the unconsumed input; - Some monoidal
log
e.g. a list of error messages; - Some
desideratum
(the object of desire) produced from the consumed input, orNothing
if the grab failed.
type Extract log desideratum = Grab () () log desideratum Source #
What is produced by performing a Dump
. Consists of:
- Some monoidal
log
e.g. a list of error messages; - Some
desideratum
(the object of desire) produced from the consumed input, orNothing
if the grab failed.
Creation
Making grabs
:: forall bag residue _r log x desideratum. Semigroup log | |
=> Grab bag residue log x | The first grab a, whose desideratum |
-> Grab x _r log desideratum | The second grab b. The residue of this grab will be
ignored, so it usually ought to be a |
-> Grab bag residue log desideratum | A grab whose result is the residue of a, the combined logs of both a and b, and the desideratum of b. |
a / b
is a pipeline of two grabs, using the output of a
as the input to b.
Making dumps
Making extracts
:: forall log desideratum. log | Log output such as an error message. |
-> Extract log desideratum | An extract with the given log and no desideratum. |
:: forall log. log | Log output such as a warning message. |
-> Extract log () | An extract with the given log and a desideratum of |
:: forall log desideratum. log | Log output, such as an error or warning message. |
-> Maybe desideratum |
|
-> Extract log desideratum | An extract consisting of the given log and desideratum. |
The most general way to construct an Extract
.
Use
Applying a grab to an input
:: forall bag residue log desideratum. Grab bag residue log desideratum | A grab, which may consume some portion of the input. |
-> bag | The input. |
-> Result residue log desideratum | The result of performing the grab, which consists of
the |
When residue
is ()
, this function specializes to runDump
.
:: forall bag log desideratum. Dump bag log desideratum | A dump which consumes the input. |
-> bag | The input. |
-> Extract log desideratum | The result extracted from the input, which
consists of a |
This is a specialization of the more general runGrab
function.
Deconstructing results
Both applying and deconstructing
runGrabMaybe :: forall bag residue log desideratum. Grab bag residue log desideratum -> bag -> Maybe desideratum Source #
Run a grab, ignoring the residue and log, producing only the desideratum.
runGrabMaybe x = desideratum . runGrab x