liveBook · Manning

Satisfy

As explained in Learn Haskell by Example

satisfy is an Attoparsec parser combinator that accepts an input character when a supplied predicate succeeds.

satisfy is an Attoparsec parser combinator that accepts an input character when a supplied predicate succeeds. Use it when valid characters are defined by a condition rather than a fixed string. section 12.2.2

Parsing whitespace

A whitespace parser accepts exactly the characters allowed by the PNM format, then void discards the parsed character: `whitespace = void $ C8.satisfy $ \c -> c == ' ' || c == '\n' || c == '\t' || c == '\r' || c == '\v' || c == '\f'`. section 12.2.2

Listing 12.20 A parser to skip whitespaces
import Control.Monad (void)

...

whitespace :: Parser ()
whitespace =
  void $                 #1
    C8.satisfy $     #2
      \c ->            #3
        c == ' '
          || c == '\n'
          || c == '\t'
          || c == '\r'
          || c == '\v'
          || c == '\f'

whitespaces :: Parser ()
whitespaces = skipMany1 whitespace     #4

Inspect the complete whitespace parser and see how satisfy combines with void and skipMany1. section 12.2.2

How Learn Haskell by Example covers it

How deep it goes
Defines predicate acceptance and demonstrates a complete whitespace parser, without exploring Attoparsec internals.
Examples
Uses PNM whitespace characters as the concrete predicate and combines the parser with skipMany1.
What you can do after
Apply it via Attoparsec to accept characters matching a custom predicate.
How it connects
Connects character predicates with parser combinators, void, skipMany1, and whitespace handling.

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.