@@ -366,10 +366,34 @@ can be used and manipulated as below.
366366
367367 Returns a parser which, if the initial parser is successful, passes the
368368 result to ``fn ``, and continues with the parser returned from ``fn ``. This
369- is the monadic binding operation. However, since we don't have Haskell's
370- ``do `` notation in Python, using this is very awkward. Instead, you should
371- look at :doc: `/ref/generating/ ` which provides a much nicer syntax for that
372- cases where you would have needed ``do `` notation in Parsec.
369+ is the monadic binding operation.
370+
371+ Here is an example that implements `Hollerith constants
372+ <https://en.wikipedia.org/wiki/Hollerith_constant> `_:
373+
374+ .. code-block :: python
375+
376+
377+ from parsy import regex, string, any_char
378+
379+ hollerith = (regex(r ' [0-9 ]+ ' ).map(int ) << string(' H' )).bind(
380+ lambda num : any_char.times(num).concat()
381+ )
382+
383+ The first parser ``(regex(r'[0-9]+').map(int) << string('H')) `` will
384+ consume something like ``"8H" `` and produce the integer ``8 ``. Via
385+ ``bind ``, we then pass that value as ``num `` into the lambda, which can
386+ use it to consume more input.
387+
388+ However, since we don't have Haskell's ``do `` notation in Python, for
389+ longer examples this is quite awkward. Instead, you should look at
390+ :doc: `/ref/generating/ ` which provides a much nicer syntax for that cases
391+ where you would have needed ``do `` notation in Parsec.
392+
393+ Also, the methods :meth: `~Parser.map `, :meth: `~Parser.combine ` and
394+ :meth: `~Parser.combine_dict `, which all use ``bind `` internally, are often
395+ more convenient ways to chain output where you are doing transformations
396+ but not further consuming of input.
373397
374398 .. method :: sep_by(sep, min=0, max=inf)
375399
0 commit comments